@@ -68,45 +68,18 @@ the compiler a chance to observe that you accessed the data for
6868
6969### Identifiers in the HIR
7070
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 ] .
9978
10079[ `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
10181[ `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
11083
11184### The HIR Map
11285
@@ -129,6 +102,7 @@ something outside of the current crate (since then it has no HIR
129102node), but otherwise returns ` Some(n) ` where ` n ` is the node-id of the
130103definition.
131104
105+ [ `NodeId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/node_id/struct.NodeId.html
132106[ as_local_node_id ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.as_local_node_id
133107
134108Similarly, you can use [ ` tcx.hir.find(n) ` ] [ find ] to lookup the node for a
0 commit comments