22
33The AST lowering step converts AST to [ HIR] ( ../hir.md ) .
44This means many structures are removed if they are irrelevant
5- for type analysis or similar syntax agnostic analyses.
5+ for type analysis or similar syntax- agnostic analyses.
66Examples of such structures include but are not limited to
77
88* Parenthesis
@@ -40,21 +40,21 @@ Lowering needs to uphold several invariants in order to not trigger the
4040sanity checks in [ ` compiler/rustc_passes/src/hir_id_validator.rs ` ] [ hir_id_validator ] :
4141
42421 . A ` HirId ` must be used if created.
43- So if you use the ` lower_node_id ` ,
44- you * must* use the resulting ` NodeId ` or ` HirId ` (either is fine, since
45- any ` NodeId ` s in the ` HIR ` are checked for existing ` HirId ` s)
43+ So, if you use the ` lower_node_id ` ,
44+ you * must* use the resulting ` NodeId ` or ` HirId ` (either is fine, since
45+ any ` NodeId ` s in the ` HIR ` are checked for existing ` HirId ` s).
46462 . Lowering a ` HirId ` must be done in the scope of the * owning* item.
47- This means you need to use ` with_hir_id_owner ` if you are creating parts
48- of an item other than the one being currently lowered.
49- This happens for example during the lowering of existential ` impl Trait `
47+ This means you need to use ` with_hir_id_owner ` if you are creating parts
48+ of an item other than the one being currently lowered.
49+ This happens, for example, during the lowering of existential ` impl Trait ` .
50503 . A ` NodeId ` that will be placed into a HIR structure must be lowered,
51- even if its ` HirId ` is unused.
52- Calling ` let _ = self.lower_node_id(node_id); ` is perfectly legitimate.
51+ even if its ` HirId ` is unused.
52+ Calling ` let _ = self.lower_node_id(node_id); ` is perfectly legitimate.
53534 . If you are creating new nodes that didn't exist in the ` AST ` , you * must*
54- create new ids for them.
55- This is done by calling the ` next_id ` method,
56- which produces both a new ` NodeId ` as well as automatically lowering it
57- for you so you also get the ` HirId ` .
54+ create new ids for them.
55+ This is done by calling the ` next_id ` method,
56+ which produces both a new ` NodeId ` as well as automatically lowering it
57+ for you so you also get the ` HirId ` .
5858
5959[ `rustc_ast_lowering` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast_lowering/index.html
6060[ `lower_to_hir` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast_lowering/fn.lower_to_hir.html
@@ -74,7 +74,7 @@ the advantage of creating a way to find the `DefId` of something via its
7474If lowering needs this ` DefId ` in multiple places, you can't
7575generate a new ` NodeId ` in all those places because you'd also get a new
7676` DefId ` then.
77- With a ` NodeId ` from the ` AST ` this is not an issue.
77+ With a ` NodeId ` from the ` AST ` , this is not an issue.
7878
7979Having the ` NodeId ` also allows the ` DefCollector ` to generate the ` DefId ` s
8080instead of lowering having to do it on the fly.
0 commit comments