Skip to main content

rustc_hir_id/
definitions.rs

1//! For each definition, we track the following data. A definition
2//! here is defined somewhat circularly as "something with a `DefId`",
3//! but it generally corresponds to things like structs, enums, etc.
4//! There are also some rather random cases (like const initializer
5//! expressions) that are mostly just leftovers.
6
7use std::fmt::{self, Write};
8use std::hash::Hash;
9
10use rustc_data_structures::fx::FxHashMap;
11use rustc_data_structures::stable_hash::StableHasher;
12use rustc_hashes::Hash64;
13use rustc_index::IndexVec;
14use rustc_macros::{BlobDecodable, Decodable, Encodable, extension};
15pub use rustc_span::def_id::DefPathHash;
16use rustc_span::def_id::{
17    CRATE_DEF_INDEX, CrateNum, DefIndex, LOCAL_CRATE, LocalDefId, LocalDefIdMap, StableCrateId,
18};
19use rustc_span::{Symbol, kw, sym};
20use tracing::{debug, instrument};
21
22use crate::def_path_hash_map::DefPathHashMap;
23
24#[derive(#[automatically_derived]
impl ::core::fmt::Debug for PerParentDisambiguatorState {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "PerParentDisambiguatorState", "parent", &self.parent, "next",
            &&self.next)
    }
}Debug, #[automatically_derived]
impl ::core::default::Default for PerParentDisambiguatorState {
    #[inline]
    fn default() -> PerParentDisambiguatorState {
        PerParentDisambiguatorState {
            parent: ::core::default::Default::default(),
            next: ::core::default::Default::default(),
        }
    }
}Default, #[automatically_derived]
impl ::core::clone::Clone for PerParentDisambiguatorState {
    #[inline]
    fn clone(&self) -> PerParentDisambiguatorState {
        PerParentDisambiguatorState {
            parent: ::core::clone::Clone::clone(&self.parent),
            next: ::core::clone::Clone::clone(&self.next),
        }
    }
}Clone)]
25pub struct PerParentDisambiguatorState {
26    #[cfg(debug_assertions)]
27    parent: Option<LocalDefId>,
28    next: FxHashMap<DefPathData, u32>,
29}
30
31impl PerParentDisambiguatorState {
32    #[inline(always)]
33    pub fn new(_parent: LocalDefId) -> PerParentDisambiguatorState {
34        PerParentDisambiguatorState {
35            #[cfg(debug_assertions)]
36            parent: Some(_parent),
37            next: Default::default(),
38        }
39    }
40}
41
42impl PerParentDisambiguatorsMap for LocalDefIdMap<PerParentDisambiguatorState>
    {
    fn get_or_create(&mut self, parent: LocalDefId)
        -> &mut PerParentDisambiguatorState {
        self.entry(parent).or_insert_with(||
                PerParentDisambiguatorState::new(parent))
    }
}#[extension(pub trait PerParentDisambiguatorsMap)]
43impl LocalDefIdMap<PerParentDisambiguatorState> {
44    fn get_or_create(&mut self, parent: LocalDefId) -> &mut PerParentDisambiguatorState {
45        self.entry(parent).or_insert_with(|| PerParentDisambiguatorState::new(parent))
46    }
47}
48
49#[derive(#[automatically_derived]
impl ::core::fmt::Debug for Definitions {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field4_finish(f, "Definitions",
            "stable_crate_id", &self.stable_crate_id, "def_id_to_key",
            &self.def_id_to_key, "def_path_hashes", &self.def_path_hashes,
            "def_path_hash_to_index", &&self.def_path_hash_to_index)
    }
}Debug)]
50pub struct Definitions {
51    stable_crate_id: StableCrateId,
52    def_id_to_key: IndexVec<LocalDefId, DefKey>,
53    // We do only store the local hash, as all the definitions are from the current crate.
54    def_path_hashes: IndexVec<LocalDefId, Hash64>,
55    def_path_hash_to_index: DefPathHashMap,
56}
57
58/// A unique identifier that we can use to lookup a definition
59/// precisely. It combines the index of the definition's parent (if
60/// any) with a `DisambiguatedDefPathData`.
61#[derive(#[automatically_derived]
impl ::core::marker::Copy for DefKey { }Copy, #[automatically_derived]
impl ::core::clone::Clone for DefKey {
    #[inline]
    fn clone(&self) -> DefKey {
        let _: ::core::clone::AssertParamIsClone<Option<DefIndex>>;
        let _: ::core::clone::AssertParamIsClone<DisambiguatedDefPathData>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for DefKey {
    #[inline]
    fn eq(&self, other: &DefKey) -> bool {
        self.parent == other.parent &&
            self.disambiguated_data == other.disambiguated_data
    }
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for DefKey {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "DefKey",
            "parent", &self.parent, "disambiguated_data",
            &&self.disambiguated_data)
    }
}Debug, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for DefKey {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    DefKey {
                        parent: ref __binding_0, disambiguated_data: ref __binding_1
                        } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::BlobDecoder> ::rustc_serialize::Decodable<__D>
            for DefKey {
            fn decode(__decoder: &mut __D) -> Self {
                DefKey {
                    parent: ::rustc_serialize::Decodable::decode(__decoder),
                    disambiguated_data: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };BlobDecodable)]
62pub struct DefKey {
63    /// The parent path.
64    pub parent: Option<DefIndex>,
65
66    /// The identifier of this node.
67    pub disambiguated_data: DisambiguatedDefPathData,
68}
69
70impl DefKey {
71    pub(crate) fn compute_stable_hash(&self, parent: DefPathHash) -> DefPathHash {
72        let mut hasher = StableHasher::new();
73
74        // The new path is in the same crate as `parent`, and will contain the stable_crate_id.
75        // Therefore, we only need to include information of the parent's local hash.
76        parent.local_hash().hash(&mut hasher);
77
78        let DisambiguatedDefPathData { ref data, disambiguator } = self.disambiguated_data;
79
80        std::mem::discriminant(data).hash(&mut hasher);
81        if let Some(name) = data.hashed_symbol() {
82            // Get a stable hash by considering the symbol chars rather than
83            // the symbol index.
84            name.as_str().hash(&mut hasher);
85        }
86
87        disambiguator.hash(&mut hasher);
88
89        let local_hash = hasher.finish();
90
91        // Construct the new DefPathHash, making sure that the `crate_id`
92        // portion of the hash is properly copied from the parent. This way the
93        // `crate_id` part will be recursively propagated from the root to all
94        // DefPathHashes in this Definitions.
95        DefPathHash::new(parent.stable_crate_id(), local_hash)
96    }
97
98    #[inline]
99    pub fn get_opt_name(&self) -> Option<Symbol> {
100        self.disambiguated_data.data.get_opt_name()
101    }
102}
103
104/// A pair of `DefPathData` and an integer disambiguator. The integer is
105/// normally `0`, but in the event that there are multiple defs with the
106/// same `parent` and `data`, we use this field to disambiguate
107/// between them. This introduces some artificial ordering dependency
108/// but means that if you have, e.g., two impls for the same type in
109/// the same module, they do get distinct `DefId`s.
110#[derive(#[automatically_derived]
impl ::core::marker::Copy for DisambiguatedDefPathData { }Copy, #[automatically_derived]
impl ::core::clone::Clone for DisambiguatedDefPathData {
    #[inline]
    fn clone(&self) -> DisambiguatedDefPathData {
        let _: ::core::clone::AssertParamIsClone<DefPathData>;
        let _: ::core::clone::AssertParamIsClone<u32>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for DisambiguatedDefPathData {
    #[inline]
    fn eq(&self, other: &DisambiguatedDefPathData) -> bool {
        self.disambiguator == other.disambiguator && self.data == other.data
    }
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for DisambiguatedDefPathData {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "DisambiguatedDefPathData", "data", &self.data, "disambiguator",
            &&self.disambiguator)
    }
}Debug, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for DisambiguatedDefPathData {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    DisambiguatedDefPathData {
                        data: ref __binding_0, disambiguator: ref __binding_1 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::BlobDecoder> ::rustc_serialize::Decodable<__D>
            for DisambiguatedDefPathData {
            fn decode(__decoder: &mut __D) -> Self {
                DisambiguatedDefPathData {
                    data: ::rustc_serialize::Decodable::decode(__decoder),
                    disambiguator: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };BlobDecodable)]
111pub struct DisambiguatedDefPathData {
112    pub data: DefPathData,
113    pub disambiguator: u32,
114}
115
116impl DisambiguatedDefPathData {
117    pub fn as_sym(&self, verbose: bool) -> Symbol {
118        match self.data.name() {
119            DefPathDataName::Named(name) => {
120                if verbose && self.disambiguator != 0 {
121                    Symbol::intern(&::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0}#{1}", name,
                self.disambiguator))
    })format!("{}#{}", name, self.disambiguator))
122                } else {
123                    name
124                }
125            }
126            DefPathDataName::Anon { namespace } => {
127                if let DefPathData::AnonAssocTy(method) = self.data {
128                    Symbol::intern(&::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0}::{{{1}#{2}}}", method,
                namespace, self.disambiguator))
    })format!("{}::{{{}#{}}}", method, namespace, self.disambiguator))
129                } else {
130                    Symbol::intern(&::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{{{0}#{1}}}", namespace,
                self.disambiguator))
    })format!("{{{}#{}}}", namespace, self.disambiguator))
131                }
132            }
133        }
134    }
135}
136
137#[derive(#[automatically_derived]
impl ::core::clone::Clone for DefPath {
    #[inline]
    fn clone(&self) -> DefPath {
        DefPath {
            data: ::core::clone::Clone::clone(&self.data),
            krate: ::core::clone::Clone::clone(&self.krate),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for DefPath {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "DefPath",
            "data", &self.data, "krate", &&self.krate)
    }
}Debug, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for DefPath {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    DefPath { data: ref __binding_0, krate: ref __binding_1 } =>
                        {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for DefPath {
            fn decode(__decoder: &mut __D) -> Self {
                DefPath {
                    data: ::rustc_serialize::Decodable::decode(__decoder),
                    krate: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable)]
138pub struct DefPath {
139    /// The path leading from the crate root to the item.
140    pub data: Vec<DisambiguatedDefPathData>,
141
142    /// The crate root this path is relative to.
143    pub krate: CrateNum,
144}
145
146impl DefPath {
147    pub fn make<FN>(krate: CrateNum, start_index: DefIndex, mut get_key: FN) -> DefPath
148    where
149        FN: FnMut(DefIndex) -> DefKey,
150    {
151        let mut data = ::alloc::vec::Vec::new()vec![];
152        let mut index = Some(start_index);
153        loop {
154            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_id/src/definitions.rs:154",
                        "rustc_hir_id::definitions", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_id/src/definitions.rs"),
                        ::tracing_core::__macro_support::Option::Some(154u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_id::definitions"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("DefPath::make: krate={0:?} index={1:?}",
                                                    krate, index) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("DefPath::make: krate={:?} index={:?}", krate, index);
155            let p = index.unwrap();
156            let key = get_key(p);
157            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_id/src/definitions.rs:157",
                        "rustc_hir_id::definitions", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_id/src/definitions.rs"),
                        ::tracing_core::__macro_support::Option::Some(157u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_id::definitions"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("DefPath::make: key={0:?}",
                                                    key) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("DefPath::make: key={:?}", key);
158            match key.disambiguated_data.data {
159                DefPathData::CrateRoot => {
160                    if !key.parent.is_none() {
    ::core::panicking::panic("assertion failed: key.parent.is_none()")
};assert!(key.parent.is_none());
161                    break;
162                }
163                _ => {
164                    data.push(key.disambiguated_data);
165                    index = key.parent;
166                }
167            }
168        }
169        data.reverse();
170        DefPath { data, krate }
171    }
172
173    /// Returns a string representation of the `DefPath` without
174    /// the crate-prefix. This method is useful if you don't have
175    /// a `TyCtxt` available.
176    pub fn to_string_no_crate_verbose(&self) -> String {
177        let mut s = String::with_capacity(self.data.len() * 16);
178
179        for component in &self.data {
180            s.write_fmt(format_args!("::{0}", component.as_sym(true)))write!(s, "::{}", component.as_sym(true)).unwrap();
181        }
182
183        s
184    }
185
186    /// Returns a filename-friendly string of the `DefPath`, without
187    /// the crate-prefix. This method is useful if you don't have
188    /// a `TyCtxt` available.
189    pub fn to_filename_friendly_no_crate(&self) -> String {
190        let mut s = String::with_capacity(self.data.len() * 16);
191
192        let mut opt_delimiter = None;
193        for component in &self.data {
194            s.extend(opt_delimiter);
195            opt_delimiter = Some('-');
196            s.write_fmt(format_args!("{0}", component.as_sym(true)))write!(s, "{}", component.as_sym(true)).unwrap();
197        }
198
199        s
200    }
201}
202
203/// New variants should only be added in synchronization with `enum DefKind`.
204#[derive(#[automatically_derived]
impl ::core::marker::Copy for DefPathData { }Copy, #[automatically_derived]
impl ::core::clone::Clone for DefPathData {
    #[inline]
    fn clone(&self) -> DefPathData {
        let _: ::core::clone::AssertParamIsClone<Symbol>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for DefPathData {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            DefPathData::CrateRoot =>
                ::core::fmt::Formatter::write_str(f, "CrateRoot"),
            DefPathData::Impl => ::core::fmt::Formatter::write_str(f, "Impl"),
            DefPathData::ForeignMod =>
                ::core::fmt::Formatter::write_str(f, "ForeignMod"),
            DefPathData::Use => ::core::fmt::Formatter::write_str(f, "Use"),
            DefPathData::GlobalAsm =>
                ::core::fmt::Formatter::write_str(f, "GlobalAsm"),
            DefPathData::TypeNs(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "TypeNs",
                    &__self_0),
            DefPathData::ValueNs(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "ValueNs", &__self_0),
            DefPathData::MacroNs(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "MacroNs", &__self_0),
            DefPathData::LifetimeNs(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "LifetimeNs", &__self_0),
            DefPathData::Closure =>
                ::core::fmt::Formatter::write_str(f, "Closure"),
            DefPathData::Ctor => ::core::fmt::Formatter::write_str(f, "Ctor"),
            DefPathData::AnonConst =>
                ::core::fmt::Formatter::write_str(f, "AnonConst"),
            DefPathData::OpaqueTy =>
                ::core::fmt::Formatter::write_str(f, "OpaqueTy"),
            DefPathData::OpaqueLifetime(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "OpaqueLifetime", &__self_0),
            DefPathData::AnonAssocTy(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "AnonAssocTy", &__self_0),
            DefPathData::SyntheticCoroutineBody =>
                ::core::fmt::Formatter::write_str(f,
                    "SyntheticCoroutineBody"),
            DefPathData::NestedStatic =>
                ::core::fmt::Formatter::write_str(f, "NestedStatic"),
        }
    }
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for DefPathData {
    #[inline]
    fn eq(&self, other: &DefPathData) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (DefPathData::TypeNs(__self_0), DefPathData::TypeNs(__arg1_0))
                    => __self_0 == __arg1_0,
                (DefPathData::ValueNs(__self_0),
                    DefPathData::ValueNs(__arg1_0)) => __self_0 == __arg1_0,
                (DefPathData::MacroNs(__self_0),
                    DefPathData::MacroNs(__arg1_0)) => __self_0 == __arg1_0,
                (DefPathData::LifetimeNs(__self_0),
                    DefPathData::LifetimeNs(__arg1_0)) => __self_0 == __arg1_0,
                (DefPathData::OpaqueLifetime(__self_0),
                    DefPathData::OpaqueLifetime(__arg1_0)) =>
                    __self_0 == __arg1_0,
                (DefPathData::AnonAssocTy(__self_0),
                    DefPathData::AnonAssocTy(__arg1_0)) => __self_0 == __arg1_0,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for DefPathData {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<Symbol>;
    }
}Eq, #[automatically_derived]
impl ::core::hash::Hash for DefPathData {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        ::core::hash::Hash::hash(&__self_discr, state);
        match self {
            DefPathData::TypeNs(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            DefPathData::ValueNs(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            DefPathData::MacroNs(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            DefPathData::LifetimeNs(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            DefPathData::OpaqueLifetime(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            DefPathData::AnonAssocTy(__self_0) =>
                ::core::hash::Hash::hash(__self_0, state),
            _ => {}
        }
    }
}Hash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for DefPathData {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        DefPathData::CrateRoot => { 0usize }
                        DefPathData::Impl => { 1usize }
                        DefPathData::ForeignMod => { 2usize }
                        DefPathData::Use => { 3usize }
                        DefPathData::GlobalAsm => { 4usize }
                        DefPathData::TypeNs(ref __binding_0) => { 5usize }
                        DefPathData::ValueNs(ref __binding_0) => { 6usize }
                        DefPathData::MacroNs(ref __binding_0) => { 7usize }
                        DefPathData::LifetimeNs(ref __binding_0) => { 8usize }
                        DefPathData::Closure => { 9usize }
                        DefPathData::Ctor => { 10usize }
                        DefPathData::AnonConst => { 11usize }
                        DefPathData::OpaqueTy => { 12usize }
                        DefPathData::OpaqueLifetime(ref __binding_0) => { 13usize }
                        DefPathData::AnonAssocTy(ref __binding_0) => { 14usize }
                        DefPathData::SyntheticCoroutineBody => { 15usize }
                        DefPathData::NestedStatic => { 16usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    DefPathData::CrateRoot => {}
                    DefPathData::Impl => {}
                    DefPathData::ForeignMod => {}
                    DefPathData::Use => {}
                    DefPathData::GlobalAsm => {}
                    DefPathData::TypeNs(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    DefPathData::ValueNs(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    DefPathData::MacroNs(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    DefPathData::LifetimeNs(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    DefPathData::Closure => {}
                    DefPathData::Ctor => {}
                    DefPathData::AnonConst => {}
                    DefPathData::OpaqueTy => {}
                    DefPathData::OpaqueLifetime(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    DefPathData::AnonAssocTy(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    DefPathData::SyntheticCoroutineBody => {}
                    DefPathData::NestedStatic => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::BlobDecoder> ::rustc_serialize::Decodable<__D>
            for DefPathData {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { DefPathData::CrateRoot }
                    1usize => { DefPathData::Impl }
                    2usize => { DefPathData::ForeignMod }
                    3usize => { DefPathData::Use }
                    4usize => { DefPathData::GlobalAsm }
                    5usize => {
                        DefPathData::TypeNs(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    6usize => {
                        DefPathData::ValueNs(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    7usize => {
                        DefPathData::MacroNs(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    8usize => {
                        DefPathData::LifetimeNs(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    9usize => { DefPathData::Closure }
                    10usize => { DefPathData::Ctor }
                    11usize => { DefPathData::AnonConst }
                    12usize => { DefPathData::OpaqueTy }
                    13usize => {
                        DefPathData::OpaqueLifetime(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    14usize => {
                        DefPathData::AnonAssocTy(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    15usize => { DefPathData::SyntheticCoroutineBody }
                    16usize => { DefPathData::NestedStatic }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `DefPathData`, expected 0..17, actual {0}",
                                n));
                    }
                }
            }
        }
    };BlobDecodable)]
205pub enum DefPathData {
206    // Root: these should only be used for the root nodes, because
207    // they are treated specially by the `def_path` function.
208    /// The crate root (marker).
209    CrateRoot,
210
211    // Different kinds of items and item-like things:
212    /// An impl.
213    Impl,
214    /// An `extern` block.
215    ForeignMod,
216    /// A `use` item.
217    Use,
218    /// A global asm item.
219    GlobalAsm,
220    /// Something in the type namespace.
221    TypeNs(Symbol),
222    /// Something in the value namespace.
223    ValueNs(Symbol),
224    /// Something in the macro namespace.
225    MacroNs(Symbol),
226    /// Something in the lifetime namespace.
227    LifetimeNs(Symbol),
228    /// A closure expression.
229    Closure,
230
231    // Subportions of items:
232    /// Implicit constructor for a unit or tuple-like struct or enum variant.
233    Ctor,
234    /// A constant expression (see `{ast,hir}::AnonConst`).
235    AnonConst,
236    /// An existential `impl Trait` type node.
237    /// Argument position `impl Trait` have a `TypeNs` with their pretty-printed name.
238    OpaqueTy,
239    /// Used for remapped captured lifetimes in an existential `impl Trait` type node.
240    OpaqueLifetime(Symbol),
241    /// An anonymous associated type from an RPITIT. The symbol refers to the name of the method
242    /// that defined the type.
243    AnonAssocTy(Symbol),
244    /// A synthetic body for a coroutine's by-move body.
245    SyntheticCoroutineBody,
246    /// Additional static data referred to by a static.
247    NestedStatic,
248}
249
250impl Definitions {
251    #[inline(always)]
252    pub fn def_key(&self, id: LocalDefId) -> DefKey {
253        self.def_id_to_key[id]
254    }
255
256    // Log debug version of `local_def_index` (just a number), as tracing of this function
257    // is called too early and cause errors if `LocalDefId` is logged (#157238).
258    x;#[instrument(level = "trace", skip(self, id), fields(def_index=?id.local_def_index), ret)]
259    #[inline(always)]
260    pub fn def_path_hash(&self, id: LocalDefId) -> DefPathHash {
261        DefPathHash::new(self.stable_crate_id, self.def_path_hashes[id])
262    }
263
264    /// Returns the path from the crate root to `index`. The root
265    /// nodes are not included in the path (i.e., this will be an
266    /// empty vector for the crate root). For an inlined item, this
267    /// will be the path of the item in the external crate (but the
268    /// path will begin with the path to the external crate).
269    #[inline]
270    pub fn def_path(&self, id: LocalDefId) -> DefPath {
271        DefPath::make(LOCAL_CRATE, id.local_def_index, |index| {
272            self.def_key(LocalDefId { local_def_index: index })
273        })
274    }
275
276    /// Adds a root definition (no parent) and a few other reserved definitions.
277    pub fn new(stable_crate_id: StableCrateId) -> Definitions {
278        let key = DefKey {
279            parent: None,
280            disambiguated_data: DisambiguatedDefPathData {
281                data: DefPathData::CrateRoot,
282                disambiguator: 0,
283            },
284        };
285
286        // We want *both* halves of a DefPathHash to depend on the crate-id of the defining crate.
287        // The crate-id can be more easily changed than the DefPath of an item, so, in the case of
288        // a crate-local DefPathHash collision, the user can simply "roll the dice again" for all
289        // DefPathHashes in the crate by changing the crate disambiguator (e.g. via bumping the
290        // crate's version number).
291        //
292        // Children paths will only hash the local portion, and still inherit the change to the
293        // root hash.
294        let def_path_hash =
295            DefPathHash::new(stable_crate_id, Hash64::new(stable_crate_id.as_u64()));
296
297        let mut defs = Definitions {
298            stable_crate_id,
299            def_path_hashes: Default::default(),
300            def_id_to_key: Default::default(),
301            def_path_hash_to_index: Default::default(),
302        };
303
304        // Create the root definition.
305        let root = defs.allocate(key, def_path_hash);
306        {
    match (&root.local_def_index, &CRATE_DEF_INDEX) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val,
                    &*right_val, ::core::option::Option::None);
            }
        }
    }
};assert_eq!(root.local_def_index, CRATE_DEF_INDEX);
307
308        defs
309    }
310
311    fn allocate(&mut self, key: DefKey, def_path_hash: DefPathHash) -> LocalDefId {
312        // Assert that all DefPathHashes correctly contain the local crate's StableCrateId.
313        if true {
    {
        match (&self.stable_crate_id, &def_path_hash.stable_crate_id()) {
            (left_val, right_val) => {
                if !(*left_val == *right_val) {
                    let kind = ::core::panicking::AssertKind::Eq;
                    ::core::panicking::assert_failed(kind, &*left_val,
                        &*right_val, ::core::option::Option::None);
                }
            }
        }
    };
};debug_assert_eq!(self.stable_crate_id, def_path_hash.stable_crate_id());
314        let local_hash = def_path_hash.local_hash();
315
316        let def_id = self.def_id_to_key.push(key);
317        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_id/src/definitions.rs:317",
                        "rustc_hir_id::definitions", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_id/src/definitions.rs"),
                        ::tracing_core::__macro_support::Option::Some(317u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_id::definitions"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("def_id_to_key.push() - {1:?} <-> {0:?}",
                                                    def_id.local_def_index, key) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("def_id_to_key.push() - {key:?} <-> {:?}", def_id.local_def_index);
318
319        self.def_path_hashes.push(local_hash);
320        if true {
    if !(self.def_path_hashes.len() == self.def_id_to_key.len()) {
        ::core::panicking::panic("assertion failed: self.def_path_hashes.len() == self.def_id_to_key.len()")
    };
};debug_assert!(self.def_path_hashes.len() == self.def_id_to_key.len());
321
322        // Check for hash collisions of DefPathHashes. These should be
323        // exceedingly rare.
324        if let Some(existing) =
325            self.def_path_hash_to_index.insert(&local_hash, &def_id.local_def_index)
326        {
327            let def_path1 = self.def_path(LocalDefId { local_def_index: existing });
328            let def_path2 = self.def_path(def_id);
329
330            // Continuing with colliding DefPathHashes can lead to correctness
331            // issues. We must abort compilation.
332            //
333            // The likelihood of such a collision is very small, so actually
334            // running into one could be indicative of a poor hash function
335            // being used.
336            //
337            // See the documentation for DefPathHash for more information.
338            {
    ::core::panicking::panic_fmt(format_args!("found DefPathHash collision between {0:#?} and {1:#?}. Compilation cannot continue.",
            def_path1, def_path2));
};panic!(
339                "found DefPathHash collision between {def_path1:#?} and {def_path2:#?}. \
340                    Compilation cannot continue."
341            );
342        }
343
344        def_id
345    }
346
347    pub fn enumerated_keys_and_path_hashes(
348        &self,
349    ) -> impl Iterator<Item = (DefIndex, &DefKey, DefPathHash)> + ExactSizeIterator {
350        self.def_id_to_key
351            .iter_enumerated()
352            .map(move |(def_id, key)| (def_id.local_def_index, key, self.def_path_hash(def_id)))
353    }
354
355    /// Creates a definition with a parent definition.
356    /// If there are multiple definitions with the same DefPathData and the same parent, use
357    /// `disambiguator` to differentiate them. Distinct `DisambiguatorState` instances are not
358    /// guaranteed to generate unique disambiguators and should instead ensure that the `parent`
359    /// and `data` pair is distinct from other instances.
360    pub fn create_def(
361        &mut self,
362        parent: LocalDefId,
363        data: DefPathData,
364        disambiguator: &mut PerParentDisambiguatorState,
365    ) -> LocalDefId {
366        // We can't use `Debug` implementation for `LocalDefId` here, since it tries to acquire a
367        // reference to `Definitions` and we're already holding a mutable reference.
368        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_id/src/definitions.rs:368",
                        "rustc_hir_id::definitions", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_id/src/definitions.rs"),
                        ::tracing_core::__macro_support::Option::Some(368u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_id::definitions"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("create_def(parent={0}, data={1:?})",
                                                    self.def_path(parent).to_string_no_crate_verbose(), data) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
369            "create_def(parent={}, data={data:?})",
370            self.def_path(parent).to_string_no_crate_verbose(),
371        );
372
373        // The root node must be created in `new()`.
374        if !(data != DefPathData::CrateRoot) {
    ::core::panicking::panic("assertion failed: data != DefPathData::CrateRoot")
};assert!(data != DefPathData::CrateRoot);
375
376        // Find the next free disambiguator for this key.
377        let disambiguator = {
378            #[cfg(debug_assertions)]
379            if true {
    {
        match (&parent, &disambiguator.parent.expect("must be set")) {
            (left_val, right_val) => {
                if !(*left_val == *right_val) {
                    let kind = ::core::panicking::AssertKind::Eq;
                    ::core::panicking::assert_failed(kind, &*left_val,
                        &*right_val,
                        ::core::option::Option::Some(format_args!("provided parent and parent in disambiguator must be the same")));
                }
            }
        }
    };
};debug_assert_eq!(
380                parent,
381                disambiguator.parent.expect("must be set"),
382                "provided parent and parent in disambiguator must be the same"
383            );
384
385            let next_disamb = disambiguator.next.entry(data).or_insert(0);
386            let disambiguator = *next_disamb;
387            *next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow");
388            disambiguator
389        };
390        let key = DefKey {
391            parent: Some(parent.local_def_index),
392            disambiguated_data: DisambiguatedDefPathData { data, disambiguator },
393        };
394
395        let parent_hash = self.def_path_hash(parent);
396        let def_path_hash = key.compute_stable_hash(parent_hash);
397
398        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_id/src/definitions.rs:398",
                        "rustc_hir_id::definitions", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_id/src/definitions.rs"),
                        ::tracing_core::__macro_support::Option::Some(398u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_id::definitions"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("create_def: after disambiguation, key = {0:?}",
                                                    key) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("create_def: after disambiguation, key = {:?}", key);
399
400        // Create the definition.
401        self.allocate(key, def_path_hash)
402    }
403
404    #[inline(always)]
405    /// Returns `None` if the `DefPathHash` does not correspond to a `LocalDefId`
406    /// in the current compilation session. This can legitimately happen if the
407    /// `DefPathHash` is from a `DefId` in an upstream crate or, during incr. comp.,
408    /// if the `DefPathHash` is from a previous compilation session and
409    /// the def-path does not exist anymore.
410    pub fn local_def_path_hash_to_def_id(&self, hash: DefPathHash) -> Option<LocalDefId> {
411        if true {
    if !(hash.stable_crate_id() == self.stable_crate_id) {
        ::core::panicking::panic("assertion failed: hash.stable_crate_id() == self.stable_crate_id")
    };
};debug_assert!(hash.stable_crate_id() == self.stable_crate_id);
412        self.def_path_hash_to_index
413            .get(&hash.local_hash())
414            .map(|local_def_index| LocalDefId { local_def_index })
415    }
416
417    pub fn def_path_hash_to_def_index_map(&self) -> &DefPathHashMap {
418        &self.def_path_hash_to_index
419    }
420
421    pub fn num_definitions(&self) -> usize {
422        self.def_path_hashes.len()
423    }
424}
425
426#[derive(#[automatically_derived]
impl ::core::marker::Copy for DefPathDataName { }Copy, #[automatically_derived]
impl ::core::clone::Clone for DefPathDataName {
    #[inline]
    fn clone(&self) -> DefPathDataName {
        let _: ::core::clone::AssertParamIsClone<Symbol>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for DefPathDataName {
    #[inline]
    fn eq(&self, other: &DefPathDataName) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (DefPathDataName::Named(__self_0),
                    DefPathDataName::Named(__arg1_0)) => __self_0 == __arg1_0,
                (DefPathDataName::Anon { namespace: __self_0 },
                    DefPathDataName::Anon { namespace: __arg1_0 }) =>
                    __self_0 == __arg1_0,
                _ => unsafe { ::core::intrinsics::unreachable() }
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::fmt::Debug for DefPathDataName {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            DefPathDataName::Named(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Named",
                    &__self_0),
            DefPathDataName::Anon { namespace: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f, "Anon",
                    "namespace", &__self_0),
        }
    }
}Debug)]
427pub enum DefPathDataName {
428    Named(Symbol),
429    Anon { namespace: Symbol },
430}
431
432impl DefPathData {
433    pub fn get_opt_name(&self) -> Option<Symbol> {
434        use self::DefPathData::*;
435        match *self {
436            TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name)
437            | OpaqueLifetime(name) => Some(name),
438
439            Impl
440            | ForeignMod
441            | CrateRoot
442            | Use
443            | GlobalAsm
444            | Closure
445            | Ctor
446            | AnonConst
447            | OpaqueTy
448            | AnonAssocTy(..)
449            | SyntheticCoroutineBody
450            | NestedStatic => None,
451        }
452    }
453
454    fn hashed_symbol(&self) -> Option<Symbol> {
455        use self::DefPathData::*;
456        match *self {
457            TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) | AnonAssocTy(name)
458            | OpaqueLifetime(name) => Some(name),
459
460            Impl
461            | ForeignMod
462            | CrateRoot
463            | Use
464            | GlobalAsm
465            | Closure
466            | Ctor
467            | AnonConst
468            | OpaqueTy
469            | SyntheticCoroutineBody
470            | NestedStatic => None,
471        }
472    }
473
474    pub fn name(&self) -> DefPathDataName {
475        use self::DefPathData::*;
476        match *self {
477            TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name)
478            | OpaqueLifetime(name) => DefPathDataName::Named(name),
479            // Note that this does not show up in user print-outs.
480            CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
481            Impl => DefPathDataName::Anon { namespace: kw::Impl },
482            ForeignMod => DefPathDataName::Anon { namespace: kw::Extern },
483            Use => DefPathDataName::Anon { namespace: kw::Use },
484            GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm },
485            Closure => DefPathDataName::Anon { namespace: sym::closure },
486            Ctor => DefPathDataName::Anon { namespace: sym::constructor },
487            AnonConst => DefPathDataName::Anon { namespace: sym::constant },
488            OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
489            AnonAssocTy(..) => DefPathDataName::Anon { namespace: sym::anon_assoc },
490            SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic },
491            NestedStatic => DefPathDataName::Anon { namespace: sym::nested },
492        }
493    }
494}
495
496impl fmt::Display for DefPathData {
497    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
498        match self.name() {
499            DefPathDataName::Named(name) => f.write_str(name.as_str()),
500            // FIXME(#70334): this will generate legacy {{closure}}, {{impl}}, etc
501            DefPathDataName::Anon { namespace } => f.write_fmt(format_args!("{{{{{0}}}}}", namespace))write!(f, "{{{{{namespace}}}}}"),
502        }
503    }
504}