Skip to main content

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