diff options
Diffstat (limited to 'compiler/rustc_hir/src/hir_id.rs')
-rw-r--r-- | compiler/rustc_hir/src/hir_id.rs | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/compiler/rustc_hir/src/hir_id.rs b/compiler/rustc_hir/src/hir_id.rs index 060f40919..404abe2b0 100644 --- a/compiler/rustc_hir/src/hir_id.rs +++ b/compiler/rustc_hir/src/hir_id.rs @@ -1,14 +1,21 @@ use crate::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_ID}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey}; use rustc_span::{def_id::DefPathHash, HashStableContext}; -use std::fmt; +use std::fmt::{self, Debug}; -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[derive(Encodable, Decodable)] pub struct OwnerId { pub def_id: LocalDefId, } +impl Debug for OwnerId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Example: DefId(0:1 ~ aa[7697]::{use#0}) + Debug::fmt(&self.def_id, f) + } +} + impl From<OwnerId> for HirId { fn from(owner: OwnerId) -> HirId { HirId { owner, local_id: ItemLocalId::from_u32(0) } @@ -60,7 +67,7 @@ impl<CTX: HashStableContext> ToStableHashKey<CTX> for OwnerId { /// the `local_id` part of the `HirId` changing, which is a very useful property in /// incremental compilation where we have to persist things through changes to /// the code base. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[derive(Encodable, Decodable, HashStable_Generic)] #[rustc_pass_by_value] pub struct HirId { @@ -68,6 +75,14 @@ pub struct HirId { pub local_id: ItemLocalId, } +impl Debug for HirId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Example: HirId(DefId(0:1 ~ aa[7697]::{use#0}).10) + // Don't use debug_tuple to always keep this on one line. + write!(f, "HirId({:?}.{:?})", self.owner, self.local_id) + } +} + impl HirId { /// Signal local id which should never be used. pub const INVALID: HirId = @@ -104,7 +119,7 @@ impl HirId { impl fmt::Display for HirId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self) + write!(f, "{self:?}") } } @@ -133,12 +148,12 @@ rustc_index::newtype_index! { /// that is, within a `hir::Item`, `hir::TraitItem`, or `hir::ImplItem`. There is no /// guarantee that the numerical value of a given `ItemLocalId` corresponds to /// the node's position within the owning item in any way, but there is a - /// guarantee that the `LocalItemId`s within an owner occupy a dense range of + /// guarantee that the `ItemLocalId`s within an owner occupy a dense range of /// integers starting at zero, so a mapping that maps all or most nodes within /// an "item-like" to something else can be implemented by a `Vec` instead of a /// tree or hash map. #[derive(HashStable_Generic)] - pub struct ItemLocalId { .. } + pub struct ItemLocalId {} } impl ItemLocalId { @@ -146,7 +161,7 @@ impl ItemLocalId { pub const INVALID: ItemLocalId = ItemLocalId::MAX; } -// Safety: Ord is implement as just comparing the LocalItemId's numerical +// Safety: Ord is implement as just comparing the ItemLocalId's numerical // values and these are not changed by (de-)serialization. unsafe impl StableOrd for ItemLocalId {} |