@@ -68,45 +68,18 @@ the compiler a chance to observe that you accessed the data for
68
68
69
69
### Identifiers in the HIR
70
70
71
- Most of the code that has to deal with things in HIR tends not to
72
- carry around references into the HIR, but rather to carry around
73
- * identifier numbers* (or just "ids"). Right now, you will find four
74
- sorts of identifiers in active use:
75
-
76
- - [ ` DefId ` ] , which primarily names "definitions" or top-level items.
77
- - You can think of a [ ` DefId ` ] as being shorthand for a very explicit
78
- and complete path, like ` std::collections::HashMap ` . However,
79
- these paths are able to name things that are not nameable in
80
- normal Rust (e.g. impls), and they also include extra information
81
- about the crate (such as its version number, as two versions of
82
- the same crate can co-exist).
83
- - A [ ` DefId ` ] really consists of two parts, a ` CrateNum ` (which
84
- identifies the crate) and a ` DefIndex ` (which indexes into a list
85
- of items that is maintained per crate).
86
- - [ ` HirId ` ] , which combines the index of a particular item with an
87
- offset within that item.
88
- - the key point of a [ ` HirId ` ] is that it is * relative* to some item
89
- (which is named via a [ ` DefId ` ] ).
90
- - [ ` BodyId ` ] , this is an identifier that refers to a specific
91
- body (definition of a function or constant) in the crate. It is currently
92
- effectively a "newtype'd" [ ` HirId ` ] .
93
- - [ ` NodeId ` ] , which is an absolute id that identifies a single node in the HIR
94
- tree.
95
- - While these are still in common use, ** they are being slowly phased out** .
96
- - Since they are absolute within the crate, adding a new node anywhere in the
97
- tree causes the [ ` NodeId ` ] s of all subsequent code in the crate to change.
98
- This is terrible for incremental compilation, as you can perhaps imagine.
71
+ There are a bunch of different identifiers to refer to other nodes or definitions
72
+ in the HIR. In short:
73
+ - A [ ` DefId ` ] refers to a * definition* in any crate.
74
+ - A [ ` LocalDefId ` ] refers to a * definition* in the currently compiled crate.
75
+ - A [ ` HirId ` ] refers to * any node* in the HIR.
76
+
77
+ For more detailed information, check out the [ chapter on identifiers] [ ids ] .
99
78
100
79
[ `DefId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html
80
+ [ `LocalDefId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.LocalDefId.html
101
81
[ `HirId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir_id/struct.HirId.html
102
- [ `BodyId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.BodyId.html
103
- [ `NodeId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/node_id/struct.NodeId.html
104
-
105
- We also have an internal map to go from ` DefId ` to what’s called "Def path". "Def path" is like a
106
- module path but a bit more rich. For example, it may be ` crate::foo::MyStruct ` that identifies
107
- this definition uniquely. It’s a bit different than a module path because it might include a type
108
- parameter ` T ` , which you can't write in normal rust, like ` crate::foo::MyStruct::T ` . These are used
109
- in incremental compilation.
82
+ [ ids ] : ./identifiers.md#in-the-hir
110
83
111
84
### The HIR Map
112
85
0 commit comments