@@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxHashMap;
1313use rustc_data_structures:: stable_hasher:: StableHasher ;
1414use rustc_index:: vec:: IndexVec ;
1515use rustc_span:: hygiene:: ExpnId ;
16- use rustc_span:: symbol:: { sym, Symbol } ;
16+ use rustc_span:: symbol:: { kw , sym, Symbol } ;
1717
1818use std:: fmt:: Write ;
1919use 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+
430442impl 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}
0 commit comments