@@ -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:: { kw, sym, Symbol } ;
16
+ use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
17
17
18
18
use std:: fmt:: { self , Write } ;
19
19
use std:: hash:: Hash ;
@@ -155,23 +155,32 @@ pub struct DisambiguatedDefPathData {
155
155
pub disambiguator : u32 ,
156
156
}
157
157
158
- impl fmt :: Display for DisambiguatedDefPathData {
159
- fn fmt ( & self , f : & mut fmt :: Formatter < ' _ > ) -> fmt:: Result {
158
+ impl DisambiguatedDefPathData {
159
+ pub fn fmt_maybe_verbose ( & self , writer : & mut impl Write , verbose : bool ) -> fmt:: Result {
160
160
match self . data . get_name ( ) {
161
161
DefPathDataName :: Named ( name) => {
162
- if self . disambiguator == 0 {
163
- f. write_str ( & name. as_str ( ) )
162
+ if Ident :: with_dummy_span ( name) . is_raw_guess ( ) {
163
+ writer. write_str ( "r#" ) ?;
164
+ }
165
+ if self . disambiguator == 0 || !verbose {
166
+ writer. write_str ( & name. as_str ( ) )
164
167
} else {
165
- write ! ( f , "{}#{}" , name, self . disambiguator)
168
+ write ! ( writer , "{}#{}" , name, self . disambiguator)
166
169
}
167
170
}
168
171
DefPathDataName :: Anon { namespace } => {
169
- write ! ( f , "{{{}#{}}}" , namespace, self . disambiguator)
172
+ write ! ( writer , "{{{}#{}}}" , namespace, self . disambiguator)
170
173
}
171
174
}
172
175
}
173
176
}
174
177
178
+ impl fmt:: Display for DisambiguatedDefPathData {
179
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
180
+ self . fmt_maybe_verbose ( f, true )
181
+ }
182
+ }
183
+
175
184
#[ derive( Clone , Debug , Encodable , Decodable ) ]
176
185
pub struct DefPath {
177
186
/// The path leading from the crate root to the item.
@@ -419,6 +428,7 @@ impl Definitions {
419
428
}
420
429
}
421
430
431
+ #[ derive( Copy , Clone , PartialEq , Debug ) ]
422
432
pub enum DefPathDataName {
423
433
Named ( Symbol ) ,
424
434
Anon { namespace : Symbol } ,
@@ -434,7 +444,7 @@ impl DefPathData {
434
444
}
435
445
}
436
446
437
- pub fn get_name ( & self ) -> DefPathDataName {
447
+ pub fn name ( & self ) -> DefPathDataName {
438
448
use self :: DefPathData :: * ;
439
449
match * self {
440
450
TypeNs ( name) | ValueNs ( name) | MacroNs ( name) | LifetimeNs ( name) => {
@@ -454,7 +464,7 @@ impl DefPathData {
454
464
455
465
impl fmt:: Display for DefPathData {
456
466
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
457
- match self . get_name ( ) {
467
+ match self . name ( ) {
458
468
DefPathDataName :: Named ( name) => f. write_str ( & name. as_str ( ) ) ,
459
469
DefPathDataName :: Anon { namespace } => write ! ( f, "{{{{{}}}}}" , namespace) ,
460
470
}
0 commit comments