Skip to content

Commit f1878d1

Browse files
committed
Move from {{closure}}#0 syntax to {closure#0} for (def) path components
1 parent c6e4db6 commit f1878d1

File tree

93 files changed

+298
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+298
-235
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use crate::common::CodegenCx;
77
use crate::llvm;
88
use crate::llvm::debuginfo::DIScope;
99
use rustc_hir::def_id::DefId;
10-
use rustc_hir::definitions::DefPathData;
10+
use rustc_hir::definitions::{DefPathData, DefPathDataName};
11+
use rustc_span::symbol::Symbol;
1112

1213
pub fn mangled_name_of_instance<'a, 'tcx>(
1314
cx: &CodegenCx<'a, 'tcx>,
@@ -29,7 +30,12 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
2930

3031
let namespace_name = match def_key.disambiguated_data.data {
3132
DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate),
32-
data => data.as_symbol(),
33+
data => match data.get_name() {
34+
DefPathDataName::Named(name) => name,
35+
DefPathDataName::Anon { namespace } => {
36+
Symbol::intern(&format!("{{{{{}}}}}", namespace))
37+
}
38+
},
3339
};
3440
let namespace_name = namespace_name.as_str();
3541

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
use rustc_data_structures::fx::FxHashSet;
44
use rustc_hir as hir;
55
use rustc_hir::def_id::DefId;
6+
use rustc_hir::definitions::DefPathDataName;
67
use rustc_middle::ty::{self, subst::SubstsRef, Ty, TyCtxt};
78

9+
use std::fmt::Write;
10+
811
// Compute the name of the type as it should be stored in debuginfo. Does not do
912
// any caching, i.e., calling the function twice with the same type will also do
1013
// the work twice. The `qualified` parameter only affects the first level of the
@@ -229,7 +232,12 @@ pub fn push_debuginfo_type_name<'tcx>(
229232
output.push_str(&tcx.crate_name(def_id.krate).as_str());
230233
for path_element in tcx.def_path(def_id).data {
231234
output.push_str("::");
232-
output.push_str(&path_element.data.as_symbol().as_str());
235+
match path_element.data.get_name() {
236+
DefPathDataName::Named(name) => output.push_str(&name.as_str()),
237+
DefPathDataName::Anon { namespace } => {
238+
write!(output, "{{{{{}}}}}", namespace).unwrap()
239+
}
240+
}
233241
}
234242
} else {
235243
output.push_str(&tcx.item_name(def_id).as_str());

compiler/rustc_hir/src/definitions.rs

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxHashMap;
1313
use rustc_data_structures::stable_hasher::StableHasher;
1414
use rustc_index::vec::IndexVec;
1515
use rustc_span::hygiene::ExpnId;
16-
use rustc_span::symbol::{sym, Symbol};
16+
use rustc_span::symbol::{kw, sym, Symbol};
1717

1818
use std::fmt::Write;
1919
use std::hash::Hash;
@@ -202,7 +202,12 @@ impl DefPath {
202202
let mut s = String::with_capacity(self.data.len() * 16);
203203

204204
for component in &self.data {
205-
write!(s, "::{}[{}]", component.data.as_symbol(), component.disambiguator).unwrap();
205+
match component.data.get_name() {
206+
DefPathDataName::Named(name) => write!(s, "::{}", name).unwrap(),
207+
DefPathDataName::Anon { namespace } => {
208+
write!(s, "::{{{}#{}}}", namespace, component.disambiguator).unwrap()
209+
}
210+
}
206211
}
207212

208213
s
@@ -220,10 +225,11 @@ impl DefPath {
220225
write!(s, "::{}", crate_name_str).unwrap();
221226

222227
for component in &self.data {
223-
if component.disambiguator == 0 {
224-
write!(s, "::{}", component.data.as_symbol()).unwrap();
225-
} else {
226-
write!(s, "{}[{}]", component.data.as_symbol(), component.disambiguator).unwrap();
228+
match component.data.get_name() {
229+
DefPathDataName::Named(name) => write!(s, "::{}", name).unwrap(),
230+
DefPathDataName::Anon { namespace } => {
231+
write!(s, "{{{}#{}}}", namespace, component.disambiguator).unwrap()
232+
}
227233
}
228234
}
229235

@@ -240,10 +246,11 @@ impl DefPath {
240246
for component in &self.data {
241247
s.extend(opt_delimiter);
242248
opt_delimiter = Some('-');
243-
if component.disambiguator == 0 {
244-
write!(s, "{}", component.data.as_symbol()).unwrap();
245-
} else {
246-
write!(s, "{}[{}]", component.data.as_symbol(), component.disambiguator).unwrap();
249+
match component.data.get_name() {
250+
DefPathDataName::Named(name) => write!(s, "{}", name).unwrap(),
251+
DefPathDataName::Anon { namespace } => {
252+
write!(s, "{{{}#{}}}", namespace, component.disambiguator).unwrap()
253+
}
247254
}
248255
}
249256
s
@@ -427,6 +434,11 @@ impl Definitions {
427434
}
428435
}
429436

437+
pub enum DefPathDataName {
438+
Named(Symbol),
439+
Anon { namespace: Symbol },
440+
}
441+
430442
impl DefPathData {
431443
pub fn get_opt_name(&self) -> Option<Symbol> {
432444
use self::DefPathData::*;
@@ -437,22 +449,27 @@ impl DefPathData {
437449
}
438450
}
439451

440-
pub fn as_symbol(&self) -> Symbol {
452+
pub fn get_name(&self) -> DefPathDataName {
441453
use self::DefPathData::*;
442454
match *self {
443-
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => name,
455+
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
456+
DefPathDataName::Named(name)
457+
}
444458
// Note that this does not show up in user print-outs.
445-
CrateRoot => sym::double_braced_crate,
446-
Impl => sym::double_braced_impl,
447-
Misc => sym::double_braced_misc,
448-
ClosureExpr => sym::double_braced_closure,
449-
Ctor => sym::double_braced_constructor,
450-
AnonConst => sym::double_braced_constant,
451-
ImplTrait => sym::double_braced_opaque,
459+
CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
460+
Impl => DefPathDataName::Anon { namespace: kw::Impl },
461+
Misc => DefPathDataName::Anon { namespace: sym::misc },
462+
ClosureExpr => DefPathDataName::Anon { namespace: sym::closure },
463+
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
464+
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
465+
ImplTrait => DefPathDataName::Anon { namespace: sym::opaque },
452466
}
453467
}
454468

455469
pub fn to_string(&self) -> String {
456-
self.as_symbol().to_string()
470+
match self.get_name() {
471+
DefPathDataName::Named(name) => name.to_string(),
472+
DefPathDataName::Anon { namespace } => format!("{{{{{}}}}}", namespace),
473+
}
457474
}
458475
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
531531
disambiguated_data: &DisambiguatedDefPathData,
532532
) -> Result<Self::Path, Self::Error> {
533533
let mut path = print_prefix(self)?;
534-
path.push(disambiguated_data.data.as_symbol().to_string());
534+
path.push(disambiguated_data.data.to_string());
535535
Ok(path)
536536
}
537537
fn path_generic_args(

compiler/rustc_lint/src/context.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_errors::{struct_span_err, Applicability};
2626
use rustc_hir as hir;
2727
use rustc_hir::def::Res;
2828
use rustc_hir::def_id::{CrateNum, DefId};
29-
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
29+
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
3030
use rustc_middle::lint::LintDiagnosticBuilder;
3131
use rustc_middle::middle::privacy::AccessLevels;
3232
use rustc_middle::middle::stability;
@@ -846,7 +846,12 @@ impl<'tcx> LateContext<'tcx> {
846846
return Ok(path);
847847
}
848848

849-
path.push(disambiguated_data.data.as_symbol());
849+
path.push(match disambiguated_data.data.get_name() {
850+
DefPathDataName::Named(name) => name,
851+
DefPathDataName::Anon { namespace } => {
852+
Symbol::intern(&format!("{{{{{}}}}}", namespace))
853+
}
854+
});
850855
Ok(path)
851856
}
852857

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashMap;
1111
use rustc_hir as hir;
1212
use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
1313
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, CRATE_DEF_INDEX, LOCAL_CRATE};
14-
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
14+
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
1515
use rustc_hir::ItemKind;
1616
use rustc_session::config::TrimmedDefPaths;
1717
use rustc_span::symbol::{kw, Ident, Symbol};
@@ -1496,25 +1496,26 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
14961496
return Ok(self);
14971497
}
14981498

1499+
let name = match disambiguated_data.data.get_name() {
1500+
DefPathDataName::Named(name) => name,
1501+
DefPathDataName::Anon { namespace } => namespace,
1502+
};
1503+
14991504
// FIXME(eddyb) `name` should never be empty, but it
15001505
// currently is for `extern { ... }` "foreign modules".
1501-
let name = disambiguated_data.data.as_symbol();
15021506
if name != kw::Invalid {
15031507
if !self.empty_path {
15041508
write!(self, "::")?;
15051509
}
15061510
if Ident::with_dummy_span(name).is_raw_guess() {
15071511
write!(self, "r#")?;
15081512
}
1509-
write!(self, "{}", name)?;
15101513

1511-
// FIXME(eddyb) this will print e.g. `{{closure}}#3`, but it
1512-
// might be nicer to use something else, e.g. `{closure#3}`.
1513-
let dis = disambiguated_data.disambiguator;
1514-
let print_dis = disambiguated_data.data.get_opt_name().is_none()
1515-
|| dis != 0 && self.tcx.sess.verbose();
1516-
if print_dis {
1517-
write!(self, "#{}", dis)?;
1514+
match disambiguated_data.data.get_name() {
1515+
DefPathDataName::Named(name) => self.write_str(&name.as_str())?,
1516+
DefPathDataName::Anon { namespace } => {
1517+
write!(self, "{{{}#{}}}", namespace, disambiguated_data.disambiguator)?
1518+
}
15181519
}
15191520

15201521
self.empty_path = false;

compiler/rustc_middle/src/ty/query/profiling_support.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use measureme::{StringComponent, StringId};
44
use rustc_data_structures::fx::FxHashMap;
55
use rustc_data_structures::profiling::SelfProfiler;
66
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
7-
use rustc_hir::definitions::DefPathData;
7+
use rustc_hir::definitions::{DefPathData, DefPathDataName};
88
use rustc_query_system::query::QueryCache;
99
use rustc_query_system::query::QueryState;
1010
use std::fmt::Debug;
@@ -66,17 +66,25 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
6666
end_index = 3;
6767
}
6868
other => {
69-
name = other.as_symbol();
70-
if def_key.disambiguated_data.disambiguator == 0 {
71-
dis = "";
72-
end_index = 3;
73-
} else {
74-
write!(&mut dis_buffer[..], "[{}]", def_key.disambiguated_data.disambiguator)
69+
name = match other.get_name() {
70+
DefPathDataName::Named(name) => {
71+
dis = "";
72+
end_index = 3;
73+
name
74+
}
75+
DefPathDataName::Anon { namespace } => {
76+
write!(
77+
&mut dis_buffer[..],
78+
"[{}]",
79+
def_key.disambiguated_data.disambiguator
80+
)
7581
.unwrap();
76-
let end_of_dis = dis_buffer.iter().position(|&c| c == b']').unwrap();
77-
dis = std::str::from_utf8(&dis_buffer[..end_of_dis + 1]).unwrap();
78-
end_index = 4;
79-
}
82+
let end_of_dis = dis_buffer.iter().position(|&c| c == b']').unwrap();
83+
dis = std::str::from_utf8(&dis_buffer[..end_of_dis + 1]).unwrap();
84+
end_index = 4;
85+
namespace
86+
}
87+
};
8088
}
8189
}
8290

compiler/rustc_mir/src/interpret/intrinsics/type_name.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_hir::def_id::CrateNum;
2-
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
2+
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
33
use rustc_middle::mir::interpret::Allocation;
44
use rustc_middle::ty::{
55
self,
@@ -134,7 +134,12 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
134134

135135
self.path.push_str("::");
136136

137-
self.path.push_str(&disambiguated_data.data.as_symbol().as_str());
137+
match disambiguated_data.data.get_name() {
138+
DefPathDataName::Named(name) => self.path.write_str(&name.as_str()).unwrap(),
139+
DefPathDataName::Anon { namespace } => {
140+
write!(self.path, "{{{{{}}}}}", namespace).unwrap()
141+
}
142+
}
138143
Ok(self)
139144
}
140145

compiler/rustc_mir/src/monomorphize/partitioning/default.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::collections::hash_map::Entry;
33
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
44
use rustc_hir::def::DefKind;
55
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
6+
use rustc_hir::definitions::DefPathDataName;
67
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
78
use rustc_middle::middle::exported_symbols::SymbolExportLevel;
89
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility};
@@ -354,7 +355,12 @@ fn compute_codegen_unit_name(
354355
*cache.entry((cgu_def_id, volatile)).or_insert_with(|| {
355356
let def_path = tcx.def_path(cgu_def_id);
356357

357-
let components = def_path.data.iter().map(|part| part.data.as_symbol());
358+
let components = def_path.data.iter().map(|part| match part.data.get_name() {
359+
DefPathDataName::Named(name) => name,
360+
DefPathDataName::Anon { namespace } => {
361+
Symbol::intern(&format!("{{{{{}}}}}", namespace))
362+
}
363+
});
358364

359365
let volatile_suffix = volatile.then_some("volatile");
360366

compiler/rustc_span/src/symbol.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ symbols! {
333333
clone,
334334
clone_closures,
335335
clone_from,
336+
closure,
336337
closure_to_fn_coercion,
337338
cmp,
338339
cmpxchg16b_target_feature,
@@ -369,6 +370,8 @@ symbols! {
369370
const_trait_bound_opt_out,
370371
const_trait_impl,
371372
const_transmute,
373+
constant,
374+
constructor,
372375
contents,
373376
context,
374377
convert,
@@ -679,6 +682,7 @@ symbols! {
679682
minnumf32,
680683
minnumf64,
681684
mips_target_feature,
685+
misc,
682686
module,
683687
module_path,
684688
more_struct_aliases,

compiler/rustc_symbol_mangling/src/legacy.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
22
use rustc_hir::def_id::CrateNum;
3-
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
3+
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
44
use rustc_middle::ich::NodeIdHashingMode;
55
use rustc_middle::mir::interpret::{ConstValue, Scalar};
66
use rustc_middle::ty::print::{PrettyPrinter, Print, Printer};
@@ -316,7 +316,10 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
316316
self.path.finalize_pending_component();
317317
}
318318

319-
self.write_str(&disambiguated_data.data.as_symbol().as_str())?;
319+
match disambiguated_data.data.get_name() {
320+
DefPathDataName::Named(name) => self.write_str(&name.as_str())?,
321+
DefPathDataName::Anon { namespace } => write!(self, "{{{{{}}}}}", namespace)?,
322+
}
320323
Ok(self)
321324
}
322325
fn path_generic_args(

0 commit comments

Comments
 (0)