1 use crate::def_id::{LocalDefId, CRATE_DEF_INDEX};
4 /// Uniquely identifies a node in the HIR of the current crate. It is
5 /// composed of the `owner`, which is the `LocalDefId` of the directly enclosing
6 /// `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e., the closest "item-like"),
7 /// and the `local_id` which is unique within the given owner.
9 /// This two-level structure makes for more stable values: One can move an item
10 /// around within the source code, or add or remove stuff before it, without
11 /// the `local_id` part of the `HirId` changing, which is a very useful property in
12 /// incremental compilation where we have to persist things through changes to
14 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
15 #[derive(Encodable, Decodable)]
17 pub owner: LocalDefId,
18 pub local_id: ItemLocalId,
21 impl fmt::Display for HirId {
22 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
23 write!(f, "{:?}", self)
27 rustc_data_structures::define_id_collections!(HirIdMap, HirIdSet, HirId);
28 rustc_data_structures::define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId);
30 rustc_index::newtype_index! {
31 /// An `ItemLocalId` uniquely identifies something within a given "item-like";
32 /// that is, within a `hir::Item`, `hir::TraitItem`, or `hir::ImplItem`. There is no
33 /// guarantee that the numerical value of a given `ItemLocalId` corresponds to
34 /// the node's position within the owning item in any way, but there is a
35 /// guarantee that the `LocalItemId`s within an owner occupy a dense range of
36 /// integers starting at zero, so a mapping that maps all or most nodes within
37 /// an "item-like" to something else can be implemented by a `Vec` instead of a
39 pub struct ItemLocalId { .. }
41 rustc_data_structures::impl_stable_hash_via_hash!(ItemLocalId);
43 /// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_INDEX`.
44 pub const CRATE_HIR_ID: HirId = HirId {
45 owner: LocalDefId { local_def_index: CRATE_DEF_INDEX },
46 local_id: ItemLocalId::from_u32(0),
49 pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX;