@@ -78,18 +78,40 @@ the compiler a chance to observe that you accessed the data for
7878
7979## Identifiers in the HIR
8080
81- There are a bunch of different identifiers to refer to other nodes or definitions
82- in the HIR. In short:
83- - A [ ` DefId ` ] refers to a * definition* in any crate.
84- - A [ ` LocalDefId ` ] refers to a * definition* in the currently compiled crate.
85- - A [ ` HirId ` ] refers to * any node* in the HIR.
81+ The HIR uses a bunch of different identifiers that coexist and serve different purposes.
8682
87- For more detailed information, check out the [ chapter on identifiers] [ ids ] .
83+ - A [ ` DefId ` ] , as the name suggests, identifies a particular definition, or top-level
84+ item, in a given crate. It is composed of two parts: a [ ` CrateNum ` ] which identifies
85+ the crate the definition comes from, and a [ ` DefIndex ` ] which identifies the definition
86+ within the crate. Unlike [ ` HirId ` ] s, there isn't a [ ` DefId ` ] for every expression, which
87+ makes them more stable across compilations.
88+
89+ - A [ ` LocalDefId ` ] is basically a [ ` DefId ` ] that is known to come from the current crate.
90+ This allows us to drop the [ ` CrateNum ` ] part, and use the type system to ensure that
91+ only local definitions are passed to functions that expect a local definition.
92+
93+ - A [ ` HirId ` ] uniquely identifies a node in the HIR of the current crate. It is composed
94+ of two parts: an ` owner ` and a ` local_id ` that is unique within the ` owner ` . This
95+ combination makes for more stable values which are helpful for incremental compilation.
96+ Unlike [ ` DefId ` ] s, a [ ` HirId ` ] can refer to [ fine-grained entities] [ Node ] like expressions,
97+ but stays local to the current crate.
98+
99+ - A [ ` BodyId ` ] identifies a HIR [ ` Body ` ] in the current crate. It is currently only
100+ a wrapper around a [ ` HirId ` ] . For more info about HIR bodies, please refer to the
101+ [ HIR chapter] [ hir-bodies ] .
102+
103+ These identifiers can be converted into one another through the [ HIR map] [ map ] .
88104
89105[ `DefId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html
90106[ `LocalDefId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.LocalDefId.html
91107[ `HirId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir_id/struct.HirId.html
92- [ ids ] : ./identifiers.md#in-the-hir
108+ [ `BodyId` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.BodyId.html
109+ [ `CrateNum` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.CrateNum.html
110+ [ `DefIndex` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefIndex.html
111+ [ `Body` ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.Body.html
112+ [ hir-map ] : ./hir.md#the-hir-map
113+ [ hir-bodies ] : ./hir.md#hir-bodies
114+ [ map ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html
93115
94116## The HIR Map
95117
0 commit comments