How rustc mutate parent node AST

I am trying to design the data structure of an AST, I found that a lot of transform action(or visit) maybe need to access or change to the parent node of the current AST node, but have a mutate reference to the parent node in AST seems not a good idea (because lifetime). I want to know how rustc compiler handles the need for some transform needed to access to the parent node ?
I took a look into rustc source code, and it seems does not have a reference to the parent, and rustc_ast::visit module seems do not provide context for accessing parent node.

AFAIK rustc does not modify the AST after creating it.


The AST is mutated by macro expansion. HIR is immutable though.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.