@@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxHashMap;
13
13
use rustc_data_structures:: stable_hasher:: StableHasher ;
14
14
use rustc_index:: vec:: IndexVec ;
15
15
use rustc_span:: hygiene:: ExpnId ;
16
- use rustc_span:: symbol:: { sym, Symbol } ;
16
+ use rustc_span:: symbol:: { kw , sym, Symbol } ;
17
17
18
18
use std:: fmt:: Write ;
19
19
use std:: hash:: Hash ;
@@ -202,7 +202,12 @@ impl DefPath {
202
202
let mut s = String :: with_capacity ( self . data . len ( ) * 16 ) ;
203
203
204
204
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
+ }
206
211
}
207
212
208
213
s
@@ -220,10 +225,11 @@ impl DefPath {
220
225
write ! ( s, "::{}" , crate_name_str) . unwrap ( ) ;
221
226
222
227
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
+ }
227
233
}
228
234
}
229
235
@@ -240,10 +246,11 @@ impl DefPath {
240
246
for component in & self . data {
241
247
s. extend ( opt_delimiter) ;
242
248
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
+ }
247
254
}
248
255
}
249
256
s
@@ -427,6 +434,11 @@ impl Definitions {
427
434
}
428
435
}
429
436
437
+ pub enum DefPathDataName {
438
+ Named ( Symbol ) ,
439
+ Anon { namespace : Symbol } ,
440
+ }
441
+
430
442
impl DefPathData {
431
443
pub fn get_opt_name ( & self ) -> Option < Symbol > {
432
444
use self :: DefPathData :: * ;
@@ -437,22 +449,27 @@ impl DefPathData {
437
449
}
438
450
}
439
451
440
- pub fn as_symbol ( & self ) -> Symbol {
452
+ pub fn get_name ( & self ) -> DefPathDataName {
441
453
use self :: DefPathData :: * ;
442
454
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
+ }
444
458
// 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 } ,
452
466
}
453
467
}
454
468
455
469
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
+ }
457
474
}
458
475
}
0 commit comments