1use std::fmt::{self, Write};
8use std::hash::Hash;
9
10use rustc_data_structures::fx::FxHashMap;
11use rustc_data_structures::sorted_map::SortedMap;
12use rustc_data_structures::stable_hash::StableHasher;
13use rustc_hashes::Hash64;
14use rustc_index::IndexVec;
15use rustc_macros::{BlobDecodable, Decodable, Encodable, extension};
16use rustc_serialize::Encodable;
17pub use rustc_span::def_id::DefPathHash;
18use rustc_span::def_id::{
19 CRATE_DEF_INDEX, CrateNum, DefIndex, LOCAL_CRATE, LocalDefId, LocalDefIdMap, StableCrateId,
20};
21use rustc_span::hygiene::{HygieneRemapper, LocalExpnIdRemapper, SyntaxContextRemapper};
22use rustc_span::{SpanEncoder, Symbol, kw, sym};
23use tracing::{debug, instrument};
24
25use crate::def_path_hash_map::DefPathHashMap;
26
27#[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 next", &self.parent,
&&self.next)
}
}Debug, #[automatically_derived]impl ::core::default::Default for
PerParentDisambiguatorState {
#[inline]
fn default() -> Self {
PerParentDisambiguatorState {
parent: ::core::default::Default::default(),
next: ::core::default::Default::default(),
}
}
}Default, #[automatically_derived]impl ::core::clone::Clone for
PerParentDisambiguatorState {
#[inline]
fn clone(&self) -> Self {
PerParentDisambiguatorState {
parent: ::core::clone::Clone::clone(&self.parent),
next: ::core::clone::Clone::clone(&self.next),
}
}
}Clone)]
28pub struct PerParentDisambiguatorState {
29 #[cfg(debug_assertions)]
30 parent: Option<LocalDefId>,
31 next: FxHashMap<DefPathData, u32>,
32}
33
34impl PerParentDisambiguatorState {
35 #[inline(always)]
36 pub fn new(_parent: LocalDefId) -> PerParentDisambiguatorState {
37 PerParentDisambiguatorState {
38 #[cfg(debug_assertions)]
39 parent: Some(_parent),
40 next: Default::default(),
41 }
42 }
43}
44
45pub trait PerParentDisambiguatorsMap {
fn get_or_create(&mut self, parent: LocalDefId)
-> &mut PerParentDisambiguatorState;
}
impl 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)]
46impl LocalDefIdMap<PerParentDisambiguatorState> {
47 fn get_or_create(&mut self, parent: LocalDefId) -> &mut PerParentDisambiguatorState {
48 self.entry(parent).or_insert_with(|| PerParentDisambiguatorState::new(parent))
49 }
50}
51
52#[derive(#[automatically_derived]impl ::core::fmt::Debug for DefPathToIndexMap {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f,
"DefPathToIndexMap before_parallel_alloc after_parallel_alloc",
&self.before_parallel_alloc, &&self.after_parallel_alloc)
}
}Debug, #[automatically_derived]impl ::core::default::Default for DefPathToIndexMap {
#[inline]
fn default() -> Self {
DefPathToIndexMap {
before_parallel_alloc: ::core::default::Default::default(),
after_parallel_alloc: ::core::default::Default::default(),
}
}
}Default)]
53pub struct DefPathToIndexMap {
54 pub before_parallel_alloc: DefPathHashMap,
58
59 pub after_parallel_alloc: Option<SortedMap<Hash64, LocalDefId>>,
65}
66
67impl DefPathToIndexMap {
68 #[inline]
69 pub fn get(&self, hash: Hash64) -> Option<DefIndex> {
70 self.before_parallel_alloc.get(&hash).or_else(|| {
71 self.after_parallel_alloc
72 .as_ref()
73 .and_then(|map| map.get(&hash).map(|id| id.local_def_index))
74 })
75 }
76
77 #[inline]
82 pub fn insert(&mut self, hash: Hash64, index: DefIndex) -> Option<DefIndex> {
83 match self.after_parallel_alloc.as_mut() {
84 None => self.before_parallel_alloc.insert(&hash, &index),
85 Some(map) => {
86 if let Some(existing) = self.before_parallel_alloc.get(&hash) {
87 return Some(existing);
88 }
89
90 map.insert(hash, LocalDefId { local_def_index: index }).map(|id| id.local_def_index)
91 }
92 }
93 }
94}
95
96#[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_field5_finish(f,
"Definitions stable_crate_id def_id_to_key def_path_hashes first_non_det_index def_path_hash_to_index",
&self.stable_crate_id, &self.def_id_to_key, &self.def_path_hashes,
&self.first_non_det_index, &&self.def_path_hash_to_index)
}
}Debug)]
97pub struct Definitions {
98 stable_crate_id: StableCrateId,
99 def_id_to_key: IndexVec<LocalDefId, DefKey>,
100 def_path_hashes: IndexVec<LocalDefId, Hash64>,
102 first_non_det_index: Option<DefIndex>,
105 def_path_hash_to_index: DefPathToIndexMap,
106}
107
108#[derive(#[automatically_derived]impl ::core::marker::Copy for DefKey { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for DefKey {
}
#[automatically_derived]impl ::core::clone::Clone for DefKey {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Option<DefIndex>>;
let _: ::core::clone::AssertParamIsClone<DisambiguatedDefPathData>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for DefKey {
}
#[automatically_derived]impl ::core::cmp::PartialEq for DefKey {
#[inline]
fn eq(&self, other: &Self) -> 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 disambiguated_data", &self.parent,
&&self.disambiguated_data)
}
}Debug, 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)]
112pub struct DefKey {
113 pub parent: Option<DefIndex>,
115
116 pub disambiguated_data: DisambiguatedDefPathData,
118}
119
120impl<E: SpanEncoder> Encodable<E> for DefKey {
121 #[inline]
122 fn encode(&self, e: &mut E) {
123 e.encode_def_key(self.parent, self.disambiguated_data);
124 }
125}
126
127impl DefKey {
128 pub(crate) fn compute_stable_hash(&self, parent: DefPathHash) -> DefPathHash {
129 let mut hasher = StableHasher::new();
130
131 parent.local_hash().hash(&mut hasher);
134
135 let DisambiguatedDefPathData { ref data, disambiguator } = self.disambiguated_data;
136
137 std::mem::discriminant(data).hash(&mut hasher);
138 if let Some(name) = data.hashed_symbol() {
139 name.as_str().hash(&mut hasher);
142 }
143
144 disambiguator.hash(&mut hasher);
145
146 let local_hash = hasher.finish();
147
148 DefPathHash::new(parent.stable_crate_id(), local_hash)
153 }
154
155 #[inline]
156 pub fn get_opt_name(&self) -> Option<Symbol> {
157 self.disambiguated_data.data.get_opt_name()
158 }
159}
160
161#[derive(#[automatically_derived]impl ::core::marker::Copy for DisambiguatedDefPathData
{
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for DisambiguatedDefPathData {
}
#[automatically_derived]impl ::core::clone::Clone for DisambiguatedDefPathData
{
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<DefPathData>;
let _: ::core::clone::AssertParamIsClone<u32>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
DisambiguatedDefPathData {
}
#[automatically_derived]impl ::core::cmp::PartialEq for
DisambiguatedDefPathData {
#[inline]
fn eq(&self, other: &Self) -> 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 disambiguator", &self.data,
&&self.disambiguator)
}
}Debug, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for DisambiguatedDefPathData {
fn encode(&self, __encoder: &mut __E) {
let DisambiguatedDefPathData {
data: ref __binding_0, disambiguator: ref __binding_1 } =
*self;
::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)]
168pub struct DisambiguatedDefPathData {
169 pub data: DefPathData,
170 pub disambiguator: u32,
171}
172
173impl DisambiguatedDefPathData {
174 pub fn as_sym(&self, verbose: bool) -> Symbol {
175 match self.data.name() {
176 DefPathDataName::Named(name) => {
177 if verbose && self.disambiguator != 0 {
178 Symbol::intern(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}#{1}", name,
self.disambiguator))
})format!("{}#{}", name, self.disambiguator))
179 } else {
180 name
181 }
182 }
183 DefPathDataName::Anon { namespace } => {
184 if let DefPathData::AnonAssocTy(method) = self.data {
185 Symbol::intern(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}::{{{1}#{2}}}", method,
namespace, self.disambiguator))
})format!("{}::{{{}#{}}}", method, namespace, self.disambiguator))
186 } else {
187 Symbol::intern(&::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{{{0}#{1}}}", namespace,
self.disambiguator))
})format!("{{{}#{}}}", namespace, self.disambiguator))
188 }
189 }
190 }
191 }
192}
193
194#[derive(#[automatically_derived]impl ::core::clone::Clone for DefPath {
#[inline]
fn clone(&self) -> Self {
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 krate", &self.data, &&self.krate)
}
}Debug, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for DefPath {
fn encode(&self, __encoder: &mut __E) {
let DefPath { data: ref __binding_0, krate: ref __binding_1
} = *self;
::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)]
195pub struct DefPath {
196 pub data: Vec<DisambiguatedDefPathData>,
198
199 pub krate: CrateNum,
201}
202
203impl DefPath {
204 pub fn make<FN>(krate: CrateNum, start_index: DefIndex, mut get_key: FN) -> DefPath
205 where
206 FN: FnMut(DefIndex) -> DefKey,
207 {
208 let mut data = ::alloc::vec::Vec::new()vec![];
209 let mut index = Some(start_index);
210 loop {
211 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs:211",
"rustc_hir_id::definitions", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(211u32),
::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);
212 let p = index.unwrap();
213 let key = get_key(p);
214 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs:214",
"rustc_hir_id::definitions", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(214u32),
::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);
215 match key.disambiguated_data.data {
216 DefPathData::CrateRoot => {
217 if !key.parent.is_none() {
::core::panicking::panic("assertion failed: key.parent.is_none()")
};assert!(key.parent.is_none());
218 break;
219 }
220 _ => {
221 data.push(key.disambiguated_data);
222 index = key.parent;
223 }
224 }
225 }
226 data.reverse();
227 DefPath { data, krate }
228 }
229
230 pub fn to_string_no_crate_verbose(&self) -> String {
234 let mut s = String::with_capacity(self.data.len() * 16);
235
236 for component in &self.data {
237 s.write_fmt(format_args!("::{0}", component.as_sym(true)))write!(s, "::{}", component.as_sym(true)).unwrap();
238 }
239
240 s
241 }
242
243 pub fn to_filename_friendly_no_crate(&self) -> String {
247 let mut s = String::with_capacity(self.data.len() * 16);
248
249 let mut opt_delimiter = None;
250 for component in &self.data {
251 s.extend(opt_delimiter);
252 opt_delimiter = Some('-');
253 s.write_fmt(format_args!("{0}", component.as_sym(true)))write!(s, "{}", component.as_sym(true)).unwrap();
254 }
255
256 s
257 }
258}
259
260#[derive(#[automatically_derived]impl ::core::marker::Copy for DefPathData { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for DefPathData {
}
#[automatically_derived]impl ::core::clone::Clone for DefPathData {
#[inline]
fn clone(&self) -> Self {
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 {
Self::CrateRoot =>
::core::fmt::Formatter::write_str(f, "CrateRoot"),
Self::Impl => ::core::fmt::Formatter::write_str(f, "Impl"),
Self::ForeignMod =>
::core::fmt::Formatter::write_str(f, "ForeignMod"),
Self::Use => ::core::fmt::Formatter::write_str(f, "Use"),
Self::GlobalAsm =>
::core::fmt::Formatter::write_str(f, "GlobalAsm"),
Self::TypeNs(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"TypeNs", &__self_0),
Self::ValueNs(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ValueNs", &__self_0),
Self::MacroNs(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"MacroNs", &__self_0),
Self::LifetimeNs(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"LifetimeNs", &__self_0),
Self::Closure => ::core::fmt::Formatter::write_str(f, "Closure"),
Self::TestBinderConstraints =>
::core::fmt::Formatter::write_str(f, "TestBinderConstraints"),
Self::Ctor => ::core::fmt::Formatter::write_str(f, "Ctor"),
Self::AnonConst =>
::core::fmt::Formatter::write_str(f, "AnonConst"),
Self::OpaqueTy =>
::core::fmt::Formatter::write_str(f, "OpaqueTy"),
Self::OpaqueLifetime(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"OpaqueLifetime", &__self_0),
Self::AnonAssocTy(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"AnonAssocTy", &__self_0),
Self::SyntheticCoroutineBody =>
::core::fmt::Formatter::write_str(f,
"SyntheticCoroutineBody"),
Self::NestedStatic =>
::core::fmt::Formatter::write_str(f, "NestedStatic"),
}
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
DefPathData {
}
#[automatically_derived]impl ::core::cmp::PartialEq for DefPathData {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::TypeNs(__self_0), Self::TypeNs(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::ValueNs(__self_0), Self::ValueNs(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::MacroNs(__self_0), Self::MacroNs(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::LifetimeNs(__self_0), Self::LifetimeNs(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::OpaqueLifetime(__self_0),
Self::OpaqueLifetime(__arg1_0)) => __self_0 == __arg1_0,
(Self::AnonAssocTy(__self_0), Self::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) {
::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
state);
match self {
Self::TypeNs(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::ValueNs(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::MacroNs(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::LifetimeNs(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::OpaqueLifetime(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
Self::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::TestBinderConstraints => { 10usize }
DefPathData::Ctor => { 11usize }
DefPathData::AnonConst => { 12usize }
DefPathData::OpaqueTy => { 13usize }
DefPathData::OpaqueLifetime(ref __binding_0) => { 14usize }
DefPathData::AnonAssocTy(ref __binding_0) => { 15usize }
DefPathData::SyntheticCoroutineBody => { 16usize }
DefPathData::NestedStatic => { 17usize }
};
::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::TestBinderConstraints => {}
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::TestBinderConstraints }
11usize => { DefPathData::Ctor }
12usize => { DefPathData::AnonConst }
13usize => { DefPathData::OpaqueTy }
14usize => {
DefPathData::OpaqueLifetime(::rustc_serialize::Decodable::decode(__decoder))
}
15usize => {
DefPathData::AnonAssocTy(::rustc_serialize::Decodable::decode(__decoder))
}
16usize => { DefPathData::SyntheticCoroutineBody }
17usize => { DefPathData::NestedStatic }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `DefPathData`, expected 0..18, actual {0}",
n));
}
}
}
}
};BlobDecodable)]
262pub enum DefPathData {
263 CrateRoot,
267
268 Impl,
271 ForeignMod,
273 Use,
275 GlobalAsm,
277 TypeNs(Symbol),
279 ValueNs(Symbol),
281 MacroNs(Symbol),
283 LifetimeNs(Symbol),
285 Closure,
287 TestBinderConstraints,
288
289 Ctor,
292 AnonConst,
294 OpaqueTy,
297 OpaqueLifetime(Symbol),
299 AnonAssocTy(Symbol),
302 SyntheticCoroutineBody,
304 NestedStatic,
306}
307
308impl Definitions {
309 pub fn commit_end_of_determinism(&mut self) {
312 let prev = self.def_path_hash_to_index.after_parallel_alloc.replace(Default::default());
313 if !prev.is_none() {
{
::core::panicking::panic_fmt(format_args!("this function should be called only once"));
}
};assert!(prev.is_none(), "this function should be called only once");
314
315 let def_index = DefIndex::from_usize(self.def_id_to_key.len());
316 self.first_non_det_index.replace(def_index);
317
318 SyntaxContextRemapper::with(|mut r| r.commit_end_of_determinism());
319 LocalExpnIdRemapper::with(|mut r| r.commit_end_of_determinism());
320 }
321
322 pub fn first_non_det_index(&self) -> DefIndex {
323 self.first_non_det_index.expect("must contain index")
324 }
325
326 #[inline(always)]
327 pub fn def_key(&self, id: LocalDefId) -> DefKey {
328 self.def_id_to_key[id]
329 }
330
331 {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() || { false }
{
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("def_path_hash",
"rustc_hir_id::definitions", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(333u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_id::definitions"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("def_index")
}> =
::tracing::__macro_support::FieldName::new("def_index");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id.local_def_index)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy
:: needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: DefPathHash = loop {};
return __tracing_attr_fake_return;
}
{
DefPathHash::new(self.stable_crate_id,
self.def_path_hashes[id])
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs:333",
"rustc_hir_id::definitions", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(333u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_id::definitions"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::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(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "trace", skip(self, id), fields(def_index=?id.local_def_index), ret)]
334 #[inline(always)]
335 pub fn def_path_hash(&self, id: LocalDefId) -> DefPathHash {
336 DefPathHash::new(self.stable_crate_id, self.def_path_hashes[id])
337 }
338
339 #[inline]
345 pub fn def_path(&self, id: LocalDefId) -> DefPath {
346 DefPath::make(LOCAL_CRATE, id.local_def_index, |index| {
347 self.def_key(LocalDefId { local_def_index: index })
348 })
349 }
350
351 pub fn new(stable_crate_id: StableCrateId) -> Definitions {
353 let key = DefKey {
354 parent: None,
355 disambiguated_data: DisambiguatedDefPathData {
356 data: DefPathData::CrateRoot,
357 disambiguator: 0,
358 },
359 };
360
361 let def_path_hash =
370 DefPathHash::new(stable_crate_id, Hash64::new(stable_crate_id.as_u64()));
371
372 let mut defs = Definitions {
373 stable_crate_id,
374 def_path_hashes: Default::default(),
375 def_id_to_key: Default::default(),
376 def_path_hash_to_index: Default::default(),
377 first_non_det_index: Default::default(),
378 };
379
380 let root = defs.allocate(key, def_path_hash);
382 {
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);
383
384 defs
385 }
386
387 fn allocate(&mut self, key: DefKey, def_path_hash: DefPathHash) -> LocalDefId {
388 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());
390 let local_hash = def_path_hash.local_hash();
391
392 let def_id = self.def_id_to_key.push(key);
393 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs:393",
"rustc_hir_id::definitions", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(393u32),
::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);
394
395 self.def_path_hashes.push(local_hash);
396 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());
397
398 if let Some(existing) =
401 self.def_path_hash_to_index.insert(local_hash, def_id.local_def_index)
402 {
403 let def_path1 = self.def_path(LocalDefId { local_def_index: existing });
404 let def_path2 = self.def_path(def_id);
405
406 {
::core::panicking::panic_fmt(format_args!("found DefPathHash collision between {0:#?} and {1:#?}. Compilation cannot continue.",
def_path1, def_path2));
};panic!(
415 "found DefPathHash collision between {def_path1:#?} and {def_path2:#?}. \
416 Compilation cannot continue."
417 );
418 }
419
420 def_id
421 }
422
423 pub fn enumerated_keys_and_path_hashes(
424 &self,
425 ) -> impl Iterator<Item = (DefIndex, &DefKey, DefPathHash)> + ExactSizeIterator {
426 self.def_id_to_key
427 .iter_enumerated()
428 .map(move |(def_id, key)| (def_id.local_def_index, key, self.def_path_hash(def_id)))
429 }
430
431 pub fn create_def(
437 &mut self,
438 parent: LocalDefId,
439 data: DefPathData,
440 disambiguator: &mut PerParentDisambiguatorState,
441 ) -> LocalDefId {
442 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs:444",
"rustc_hir_id::definitions", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(444u32),
::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!(
445 "create_def(parent={}, data={data:?})",
446 self.def_path(parent).to_string_no_crate_verbose(),
447 );
448
449 if !(data != DefPathData::CrateRoot) {
::core::panicking::panic("assertion failed: data != DefPathData::CrateRoot")
};assert!(data != DefPathData::CrateRoot);
451
452 let disambiguator = {
454 #[cfg(debug_assertions)]
455 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!(
456 parent,
457 disambiguator.parent.expect("must be set"),
458 "provided parent and parent in disambiguator must be the same"
459 );
460
461 let next_disamb = disambiguator.next.entry(data).or_insert(0);
462 let disambiguator = *next_disamb;
463 *next_disamb = next_disamb.checked_add(1).expect("disambiguator overflow");
464 disambiguator
465 };
466 let key = DefKey {
467 parent: Some(parent.local_def_index),
468 disambiguated_data: DisambiguatedDefPathData { data, disambiguator },
469 };
470
471 let parent_hash = self.def_path_hash(parent);
472 let def_path_hash = key.compute_stable_hash(parent_hash);
473
474 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs:474",
"rustc_hir_id::definitions", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/1c3a6506966e21845b31de0b075d2527660db132/compiler/rustc_hir_id/src/definitions.rs"),
::tracing_core::__macro_support::Option::Some(474u32),
::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);
475
476 self.allocate(key, def_path_hash)
478 }
479
480 #[inline(always)]
481 pub fn local_def_path_hash_to_def_id(&self, hash: DefPathHash) -> Option<LocalDefId> {
487 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);
488 self.def_path_hash_to_index
489 .get(hash.local_hash())
490 .map(|local_def_index| LocalDefId { local_def_index })
491 }
492
493 pub fn def_path_hash_to_def_index_map(&self) -> &DefPathToIndexMap {
494 &self.def_path_hash_to_index
495 }
496
497 pub fn num_definitions(&self) -> usize {
498 self.def_path_hashes.len()
499 }
500}
501
502#[derive(#[automatically_derived]impl ::core::marker::Copy for DefPathDataName { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for DefPathDataName {
}
#[automatically_derived]impl ::core::clone::Clone for DefPathDataName {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<Symbol>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
DefPathDataName {
}
#[automatically_derived]impl ::core::cmp::PartialEq for DefPathDataName {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Named(__self_0), Self::Named(__arg1_0)) =>
__self_0 == __arg1_0,
(Self::Anon { namespace: __self_0 }, Self::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 {
Self::Named(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f, "Named",
&__self_0),
Self::Anon { namespace: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"Anon namespace", &__self_0),
}
}
}Debug)]
503pub enum DefPathDataName {
504 Named(Symbol),
505 Anon { namespace: Symbol },
506}
507
508impl DefPathData {
509 pub fn get_opt_name(&self) -> Option<Symbol> {
510 use self::DefPathData::*;
511 match *self {
512 TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name)
513 | OpaqueLifetime(name) => Some(name),
514
515 Impl
516 | ForeignMod
517 | CrateRoot
518 | Use
519 | GlobalAsm
520 | Closure
521 | Ctor
522 | AnonConst
523 | OpaqueTy
524 | AnonAssocTy(..)
525 | SyntheticCoroutineBody
526 | NestedStatic
527 | TestBinderConstraints => None,
528 }
529 }
530
531 fn hashed_symbol(&self) -> Option<Symbol> {
532 use self::DefPathData::*;
533 match *self {
534 TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) | AnonAssocTy(name)
535 | OpaqueLifetime(name) => Some(name),
536
537 Impl
538 | ForeignMod
539 | CrateRoot
540 | Use
541 | GlobalAsm
542 | Closure
543 | Ctor
544 | AnonConst
545 | OpaqueTy
546 | SyntheticCoroutineBody
547 | NestedStatic
548 | TestBinderConstraints => None,
549 }
550 }
551
552 pub fn name(&self) -> DefPathDataName {
553 use self::DefPathData::*;
554 match *self {
555 TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name)
556 | OpaqueLifetime(name) => DefPathDataName::Named(name),
557 CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
559 Impl => DefPathDataName::Anon { namespace: kw::Impl },
560 ForeignMod => DefPathDataName::Anon { namespace: kw::Extern },
561 Use => DefPathDataName::Anon { namespace: kw::Use },
562 GlobalAsm => DefPathDataName::Anon { namespace: sym::global_asm },
563 Closure => DefPathDataName::Anon { namespace: sym::closure },
564 Ctor => DefPathDataName::Anon { namespace: sym::constructor },
565 AnonConst => DefPathDataName::Anon { namespace: sym::constant },
566 OpaqueTy => DefPathDataName::Anon { namespace: sym::opaque },
567 AnonAssocTy(..) => DefPathDataName::Anon { namespace: sym::anon_assoc },
568 SyntheticCoroutineBody => DefPathDataName::Anon { namespace: sym::synthetic },
569 NestedStatic => DefPathDataName::Anon { namespace: sym::nested },
570 TestBinderConstraints => {
571 DefPathDataName::Anon { namespace: sym::test_binder_constraints }
572 }
573 }
574 }
575}
576
577impl fmt::Display for DefPathData {
578 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
579 match self.name() {
580 DefPathDataName::Named(name) => f.write_str(name.as_str()),
581 DefPathDataName::Anon { namespace } => f.write_fmt(format_args!("{{{{{0}}}}}", namespace))write!(f, "{{{{{namespace}}}}}"),
583 }
584 }
585}