@@ -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:: { kw, sym, Symbol } ;
16+ use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
1717
1818use std:: fmt:: { self , Write } ;
1919use std:: hash:: Hash ;
@@ -155,23 +155,32 @@ pub struct DisambiguatedDefPathData {
155155 pub disambiguator : u32 ,
156156}
157157
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 {
160160 match self . data . get_name ( ) {
161161 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 ( ) )
164167 } else {
165- write ! ( f , "{}#{}" , name, self . disambiguator)
168+ write ! ( writer , "{}#{}" , name, self . disambiguator)
166169 }
167170 }
168171 DefPathDataName :: Anon { namespace } => {
169- write ! ( f , "{{{}#{}}}" , namespace, self . disambiguator)
172+ write ! ( writer , "{{{}#{}}}" , namespace, self . disambiguator)
170173 }
171174 }
172175 }
173176}
174177
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+
175184#[ derive( Clone , Debug , Encodable , Decodable ) ]
176185pub struct DefPath {
177186 /// The path leading from the crate root to the item.
@@ -419,6 +428,7 @@ impl Definitions {
419428 }
420429}
421430
431+ #[ derive( Copy , Clone , PartialEq , Debug ) ]
422432pub enum DefPathDataName {
423433 Named ( Symbol ) ,
424434 Anon { namespace : Symbol } ,
@@ -434,7 +444,7 @@ impl DefPathData {
434444 }
435445 }
436446
437- pub fn get_name ( & self ) -> DefPathDataName {
447+ pub fn name ( & self ) -> DefPathDataName {
438448 use self :: DefPathData :: * ;
439449 match * self {
440450 TypeNs ( name) | ValueNs ( name) | MacroNs ( name) | LifetimeNs ( name) => {
@@ -454,7 +464,7 @@ impl DefPathData {
454464
455465impl fmt:: Display for DefPathData {
456466 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
457- match self . get_name ( ) {
467+ match self . name ( ) {
458468 DefPathDataName :: Named ( name) => f. write_str ( & name. as_str ( ) ) ,
459469 DefPathDataName :: Anon { namespace } => write ! ( f, "{{{{{}}}}}" , namespace) ,
460470 }
0 commit comments