about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs10
-rw-r--r--compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs10
-rw-r--r--compiler/rustc_hir/src/definitions.rs57
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/mod.rs2
-rw-r--r--compiler/rustc_lint/src/context.rs9
-rw-r--r--compiler/rustc_middle/src/ty/print/pretty.rs21
-rw-r--r--compiler/rustc_middle/src/ty/query/profiling_support.rs30
-rw-r--r--compiler/rustc_mir/src/interpret/intrinsics/type_name.rs9
-rw-r--r--compiler/rustc_mir/src/monomorphize/partitioning/default.rs8
-rw-r--r--compiler/rustc_span/src/symbol.rs4
-rw-r--r--compiler/rustc_symbol_mangling/src/legacy.rs7
11 files changed, 115 insertions, 52 deletions
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs
index d1a55335c44..835d0d2e12d 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/namespace.rs
@@ -7,7 +7,8 @@ use crate::common::CodegenCx;
 use crate::llvm;
 use crate::llvm::debuginfo::DIScope;
 use rustc_hir::def_id::DefId;
-use rustc_hir::definitions::DefPathData;
+use rustc_hir::definitions::{DefPathData, DefPathDataName};
+use rustc_span::symbol::Symbol;
 
 pub fn mangled_name_of_instance<'a, 'tcx>(
     cx: &CodegenCx<'a, 'tcx>,
@@ -29,7 +30,12 @@ pub fn item_namespace(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll DIScope {
 
     let namespace_name = match def_key.disambiguated_data.data {
         DefPathData::CrateRoot => cx.tcx.crate_name(def_id.krate),
-        data => data.as_symbol(),
+        data => match data.get_name() {
+            DefPathDataName::Named(name) => name,
+            DefPathDataName::Anon { namespace } => {
+                Symbol::intern(&format!("{{{{{}}}}}", namespace))
+            }
+        },
     };
     let namespace_name = namespace_name.as_str();
 
diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
index 0c0f1bc681c..e227f9df000 100644
--- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
+++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
@@ -3,8 +3,11 @@
 use rustc_data_structures::fx::FxHashSet;
 use rustc_hir as hir;
 use rustc_hir::def_id::DefId;
+use rustc_hir::definitions::DefPathDataName;
 use rustc_middle::ty::{self, subst::SubstsRef, Ty, TyCtxt};
 
+use std::fmt::Write;
+
 // Compute the name of the type as it should be stored in debuginfo. Does not do
 // any caching, i.e., calling the function twice with the same type will also do
 // the work twice. The `qualified` parameter only affects the first level of the
@@ -229,7 +232,12 @@ pub fn push_debuginfo_type_name<'tcx>(
             output.push_str(&tcx.crate_name(def_id.krate).as_str());
             for path_element in tcx.def_path(def_id).data {
                 output.push_str("::");
-                output.push_str(&path_element.data.as_symbol().as_str());
+                match path_element.data.get_name() {
+                    DefPathDataName::Named(name) => output.push_str(&name.as_str()),
+                    DefPathDataName::Anon { namespace } => {
+                        write!(output, "{{{{{}}}}}", namespace).unwrap()
+                    }
+                }
             }
         } else {
             output.push_str(&tcx.item_name(def_id).as_str());
diff --git a/compiler/rustc_hir/src/definitions.rs b/compiler/rustc_hir/src/definitions.rs
index 45befc7b115..c825042bdcd 100644
--- a/compiler/rustc_hir/src/definitions.rs
+++ b/compiler/rustc_hir/src/definitions.rs
@@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::stable_hasher::StableHasher;
 use rustc_index::vec::IndexVec;
 use rustc_span::hygiene::ExpnId;
-use rustc_span::symbol::{sym, Symbol};
+use rustc_span::symbol::{kw, sym, Symbol};
 
 use std::fmt::Write;
 use std::hash::Hash;
@@ -202,7 +202,12 @@ impl DefPath {
         let mut s = String::with_capacity(self.data.len() * 16);
 
         for component in &self.data {
-            write!(s, "::{}[{}]", component.data.as_symbol(), component.disambiguator).unwrap();
+            match component.data.get_name() {
+                DefPathDataName::Named(name) => write!(s, "::{}", name).unwrap(),
+                DefPathDataName::Anon { namespace } => {
+                    write!(s, "::{{{}#{}}}", namespace, component.disambiguator).unwrap()
+                }
+            }
         }
 
         s
@@ -220,10 +225,11 @@ impl DefPath {
         write!(s, "::{}", crate_name_str).unwrap();
 
         for component in &self.data {
-            if component.disambiguator == 0 {
-                write!(s, "::{}", component.data.as_symbol()).unwrap();
-            } else {
-                write!(s, "{}[{}]", component.data.as_symbol(), component.disambiguator).unwrap();
+            match component.data.get_name() {
+                DefPathDataName::Named(name) => write!(s, "::{}", name).unwrap(),
+                DefPathDataName::Anon { namespace } => {
+                    write!(s, "{{{}#{}}}", namespace, component.disambiguator).unwrap()
+                }
             }
         }
 
@@ -240,10 +246,11 @@ impl DefPath {
         for component in &self.data {
             s.extend(opt_delimiter);
             opt_delimiter = Some('-');
-            if component.disambiguator == 0 {
-                write!(s, "{}", component.data.as_symbol()).unwrap();
-            } else {
-                write!(s, "{}[{}]", component.data.as_symbol(), component.disambiguator).unwrap();
+            match component.data.get_name() {
+                DefPathDataName::Named(name) => write!(s, "{}", name).unwrap(),
+                DefPathDataName::Anon { namespace } => {
+                    write!(s, "{{{}#{}}}", namespace, component.disambiguator).unwrap()
+                }
             }
         }
         s
@@ -427,6 +434,11 @@ impl Definitions {
     }
 }
 
+pub enum DefPathDataName {
+    Named(Symbol),
+    Anon { namespace: Symbol },
+}
+
 impl DefPathData {
     pub fn get_opt_name(&self) -> Option<Symbol> {
         use self::DefPathData::*;
@@ -437,22 +449,27 @@ impl DefPathData {
         }
     }
 
-    pub fn as_symbol(&self) -> Symbol {
+    pub fn get_name(&self) -> DefPathDataName {
         use self::DefPathData::*;
         match *self {
-            TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => name,
+            TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => {
+                DefPathDataName::Named(name)
+            }
             // Note that this does not show up in user print-outs.
-            CrateRoot => sym::double_braced_crate,
-            Impl => sym::double_braced_impl,
-            Misc => sym::double_braced_misc,
-            ClosureExpr => sym::double_braced_closure,
-            Ctor => sym::double_braced_constructor,
-            AnonConst => sym::double_braced_constant,
-            ImplTrait => sym::double_braced_opaque,
+            CrateRoot => DefPathDataName::Anon { namespace: kw::Crate },
+            Impl => DefPathDataName::Anon { namespace: kw::Impl },
+            Misc => DefPathDataName::Anon { namespace: sym::misc },
+            ClosureExpr => DefPathDataName::Anon { namespace: sym::closure },
+            Ctor => DefPathDataName::Anon { namespace: sym::constructor },
+            AnonConst => DefPathDataName::Anon { namespace: sym::constant },
+            ImplTrait => DefPathDataName::Anon { namespace: sym::opaque },
         }
     }
 
     pub fn to_string(&self) -> String {
-        self.as_symbol().to_string()
+        match self.get_name() {
+            DefPathDataName::Named(name) => name.to_string(),
+            DefPathDataName::Anon { namespace } => format!("{{{{{}}}}}", namespace),
+        }
     }
 }
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
index bcfcee23d13..a99193c972b 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
@@ -531,7 +531,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                 disambiguated_data: &DisambiguatedDefPathData,
             ) -> Result<Self::Path, Self::Error> {
                 let mut path = print_prefix(self)?;
-                path.push(disambiguated_data.data.as_symbol().to_string());
+                path.push(disambiguated_data.data.to_string());
                 Ok(path)
             }
             fn path_generic_args(
diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs
index 0265fc323b3..e4b72847638 100644
--- a/compiler/rustc_lint/src/context.rs
+++ b/compiler/rustc_lint/src/context.rs
@@ -26,7 +26,7 @@ use rustc_errors::{struct_span_err, Applicability};
 use rustc_hir as hir;
 use rustc_hir::def::Res;
 use rustc_hir::def_id::{CrateNum, DefId};
-use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
+use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
 use rustc_middle::lint::LintDiagnosticBuilder;
 use rustc_middle::middle::privacy::AccessLevels;
 use rustc_middle::middle::stability;
@@ -846,7 +846,12 @@ impl<'tcx> LateContext<'tcx> {
                     return Ok(path);
                 }
 
-                path.push(disambiguated_data.data.as_symbol());
+                path.push(match disambiguated_data.data.get_name() {
+                    DefPathDataName::Named(name) => name,
+                    DefPathDataName::Anon { namespace } => {
+                        Symbol::intern(&format!("{{{{{}}}}}", namespace))
+                    }
+                });
                 Ok(path)
             }
 
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs
index c9cc9bfc9fa..91986289099 100644
--- a/compiler/rustc_middle/src/ty/print/pretty.rs
+++ b/compiler/rustc_middle/src/ty/print/pretty.rs
@@ -11,7 +11,7 @@ use rustc_data_structures::fx::FxHashMap;
 use rustc_hir as hir;
 use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
 use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, CRATE_DEF_INDEX, LOCAL_CRATE};
-use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
+use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
 use rustc_hir::ItemKind;
 use rustc_session::config::TrimmedDefPaths;
 use rustc_span::symbol::{kw, Ident, Symbol};
@@ -1496,9 +1496,13 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
             return Ok(self);
         }
 
+        let name = match disambiguated_data.data.get_name() {
+            DefPathDataName::Named(name) => name,
+            DefPathDataName::Anon { namespace } => namespace,
+        };
+
         // FIXME(eddyb) `name` should never be empty, but it
         // currently is for `extern { ... }` "foreign modules".
-        let name = disambiguated_data.data.as_symbol();
         if name != kw::Invalid {
             if !self.empty_path {
                 write!(self, "::")?;
@@ -1506,15 +1510,12 @@ impl<F: fmt::Write> Printer<'tcx> for FmtPrinter<'_, 'tcx, F> {
             if Ident::with_dummy_span(name).is_raw_guess() {
                 write!(self, "r#")?;
             }
-            write!(self, "{}", name)?;
 
-            // FIXME(eddyb) this will print e.g. `{{closure}}#3`, but it
-            // might be nicer to use something else, e.g. `{closure#3}`.
-            let dis = disambiguated_data.disambiguator;
-            let print_dis = disambiguated_data.data.get_opt_name().is_none()
-                || dis != 0 && self.tcx.sess.verbose();
-            if print_dis {
-                write!(self, "#{}", dis)?;
+            match disambiguated_data.data.get_name() {
+                DefPathDataName::Named(name) => self.write_str(&name.as_str())?,
+                DefPathDataName::Anon { namespace } => {
+                    write!(self, "{{{}#{}}}", namespace, disambiguated_data.disambiguator)?
+                }
             }
 
             self.empty_path = false;
diff --git a/compiler/rustc_middle/src/ty/query/profiling_support.rs b/compiler/rustc_middle/src/ty/query/profiling_support.rs
index 9b1837356e3..cecb58eb024 100644
--- a/compiler/rustc_middle/src/ty/query/profiling_support.rs
+++ b/compiler/rustc_middle/src/ty/query/profiling_support.rs
@@ -4,7 +4,7 @@ use measureme::{StringComponent, StringId};
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::profiling::SelfProfiler;
 use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
-use rustc_hir::definitions::DefPathData;
+use rustc_hir::definitions::{DefPathData, DefPathDataName};
 use rustc_query_system::query::QueryCache;
 use rustc_query_system::query::QueryState;
 use std::fmt::Debug;
@@ -66,17 +66,25 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
                 end_index = 3;
             }
             other => {
-                name = other.as_symbol();
-                if def_key.disambiguated_data.disambiguator == 0 {
-                    dis = "";
-                    end_index = 3;
-                } else {
-                    write!(&mut dis_buffer[..], "[{}]", def_key.disambiguated_data.disambiguator)
+                name = match other.get_name() {
+                    DefPathDataName::Named(name) => {
+                        dis = "";
+                        end_index = 3;
+                        name
+                    }
+                    DefPathDataName::Anon { namespace } => {
+                        write!(
+                            &mut dis_buffer[..],
+                            "[{}]",
+                            def_key.disambiguated_data.disambiguator
+                        )
                         .unwrap();
-                    let end_of_dis = dis_buffer.iter().position(|&c| c == b']').unwrap();
-                    dis = std::str::from_utf8(&dis_buffer[..end_of_dis + 1]).unwrap();
-                    end_index = 4;
-                }
+                        let end_of_dis = dis_buffer.iter().position(|&c| c == b']').unwrap();
+                        dis = std::str::from_utf8(&dis_buffer[..end_of_dis + 1]).unwrap();
+                        end_index = 4;
+                        namespace
+                    }
+                };
             }
         }
 
diff --git a/compiler/rustc_mir/src/interpret/intrinsics/type_name.rs b/compiler/rustc_mir/src/interpret/intrinsics/type_name.rs
index 8c0014e10d0..8cf768a006b 100644
--- a/compiler/rustc_mir/src/interpret/intrinsics/type_name.rs
+++ b/compiler/rustc_mir/src/interpret/intrinsics/type_name.rs
@@ -1,5 +1,5 @@
 use rustc_hir::def_id::CrateNum;
-use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
+use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
 use rustc_middle::mir::interpret::Allocation;
 use rustc_middle::ty::{
     self,
@@ -134,7 +134,12 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
 
         self.path.push_str("::");
 
-        self.path.push_str(&disambiguated_data.data.as_symbol().as_str());
+        match disambiguated_data.data.get_name() {
+            DefPathDataName::Named(name) => self.path.write_str(&name.as_str()).unwrap(),
+            DefPathDataName::Anon { namespace } => {
+                write!(self.path, "{{{{{}}}}}", namespace).unwrap()
+            }
+        }
         Ok(self)
     }
 
diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs
index 827d037f319..c9622df099f 100644
--- a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs
+++ b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs
@@ -3,6 +3,7 @@ use std::collections::hash_map::Entry;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_hir::def::DefKind;
 use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
+use rustc_hir::definitions::DefPathDataName;
 use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
 use rustc_middle::middle::exported_symbols::SymbolExportLevel;
 use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility};
@@ -354,7 +355,12 @@ fn compute_codegen_unit_name(
     *cache.entry((cgu_def_id, volatile)).or_insert_with(|| {
         let def_path = tcx.def_path(cgu_def_id);
 
-        let components = def_path.data.iter().map(|part| part.data.as_symbol());
+        let components = def_path.data.iter().map(|part| match part.data.get_name() {
+            DefPathDataName::Named(name) => name,
+            DefPathDataName::Anon { namespace } => {
+                Symbol::intern(&format!("{{{{{}}}}}", namespace))
+            }
+        });
 
         let volatile_suffix = volatile.then_some("volatile");
 
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 2d5c6451d1a..a63e9e933ae 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -333,6 +333,7 @@ symbols! {
         clone,
         clone_closures,
         clone_from,
+        closure,
         closure_to_fn_coercion,
         cmp,
         cmpxchg16b_target_feature,
@@ -369,6 +370,8 @@ symbols! {
         const_trait_bound_opt_out,
         const_trait_impl,
         const_transmute,
+        constant,
+        constructor,
         contents,
         context,
         convert,
@@ -679,6 +682,7 @@ symbols! {
         minnumf32,
         minnumf64,
         mips_target_feature,
+        misc,
         module,
         module_path,
         more_struct_aliases,
diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs
index 6f9fc115cae..15eab8bb857 100644
--- a/compiler/rustc_symbol_mangling/src/legacy.rs
+++ b/compiler/rustc_symbol_mangling/src/legacy.rs
@@ -1,6 +1,6 @@
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc_hir::def_id::CrateNum;
-use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
+use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
 use rustc_middle::ich::NodeIdHashingMode;
 use rustc_middle::mir::interpret::{ConstValue, Scalar};
 use rustc_middle::ty::print::{PrettyPrinter, Print, Printer};
@@ -316,7 +316,10 @@ impl Printer<'tcx> for SymbolPrinter<'tcx> {
             self.path.finalize_pending_component();
         }
 
-        self.write_str(&disambiguated_data.data.as_symbol().as_str())?;
+        match disambiguated_data.data.get_name() {
+            DefPathDataName::Named(name) => self.write_str(&name.as_str())?,
+            DefPathDataName::Anon { namespace } => write!(self, "{{{{{}}}}}", namespace)?,
+        }
         Ok(self)
     }
     fn path_generic_args(