File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -32,4 +32,16 @@ sanity checks in `src/librustc/hir/map/hir_id_validator.rs`:
32
32
4 . If you are creating new nodes that didn't exist in the ` AST ` , you * must*
33
33
create new ids for them. This is done by calling the ` next_id ` method,
34
34
which produces both a new ` NodeId ` as well as automatically lowering it
35
- for you so you also get the ` HirId ` .
35
+ for you so you also get the ` HirId ` .
36
+
37
+ If you are creating new ` DefId ` s, since each ` DefId ` needs to have a corresponding
38
+ ` NodeId ` , it is adviseable to add these ` NodeId ` s to the ` AST ` so you don't have
39
+ to generate new ones during lowering. This has the advantage of creating a
40
+ way to find the ` DefId ` of something via its ` NodeId ` . If lowering needs this
41
+ ` DefId ` in multiple places, you can't generate a new ` NodeId ` in all those places
42
+ because you'd also get a new ` DefId ` then. With a ` NodeId ` from the ` AST ` this is
43
+ not an issue.
44
+
45
+ Having the ` NodeId ` also allows the ` DefCollector ` to generate the ` DefId ` s instead
46
+ of lowering having to do it on the fly. Centralizing the ` DefId ` generation in one
47
+ place makes it easier to refactor and reason about.
You can’t perform that action at this time.
0 commit comments