@@ -43,7 +43,7 @@ use rustc_errors::Applicability;
4343use syntax:: ast:: { self , LitKind } ;
4444use syntax:: attr;
4545use syntax:: source_map:: { Span , DUMMY_SP } ;
46- use syntax:: symbol:: { keywords, Symbol } ;
46+ use syntax:: symbol:: { keywords, Symbol , LocalInternedString } ;
4747
4848use crate :: reexport:: * ;
4949
@@ -107,7 +107,7 @@ use rustc::ty::print::Printer;
107107impl < ' tcx > Printer < ' tcx , ' tcx > for AbsolutePathPrinter < ' _ , ' tcx > {
108108 type Error = !;
109109
110- type Path = Vec < String > ;
110+ type Path = Vec < LocalInternedString > ;
111111 type Region = ( ) ;
112112 type Type = ( ) ;
113113 type DynExistential = ( ) ;
@@ -141,17 +141,18 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
141141 self ,
142142 cnum : CrateNum ,
143143 ) -> Result < Self :: Path , Self :: Error > {
144- Ok ( vec ! [ self . tcx. original_crate_name( cnum) . to_string ( ) ] )
144+ Ok ( vec ! [ self . tcx. original_crate_name( cnum) . as_str ( ) ] )
145145 }
146+
146147 fn path_qualified (
147148 self ,
148149 self_ty : Ty < ' tcx > ,
149150 trait_ref : Option < ty:: TraitRef < ' tcx > > ,
150151 ) -> Result < Self :: Path , Self :: Error > {
151152 // This shouldn't ever be needed, but just in case:
152153 Ok ( vec ! [ match trait_ref {
153- Some ( trait_ref) => format!( "{:?}" , trait_ref) ,
154- None => format!( "<{}>" , self_ty) ,
154+ Some ( trait_ref) => Symbol :: intern ( & format!( "{:?}" , trait_ref) ) . as_str ( ) ,
155+ None => Symbol :: intern ( & format!( "<{}>" , self_ty) ) . as_str ( ) ,
155156 } ] )
156157 }
157158
@@ -167,22 +168,24 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
167168 // This shouldn't ever be needed, but just in case:
168169 path. push ( match trait_ref {
169170 Some ( trait_ref) => {
170- format ! ( "<impl {} for {}>" , trait_ref, self_ty)
171+ Symbol :: intern ( & format ! ( "<impl {} for {}>" , trait_ref, self_ty) ) . as_str ( )
171172 }
172- None => format ! ( "<impl {}>" , self_ty) ,
173+ None => Symbol :: intern ( & format ! ( "<impl {}>" , self_ty) ) . as_str ( ) ,
173174 } ) ;
174175
175176 Ok ( path)
176177 }
178+
177179 fn path_append (
178180 self ,
179181 print_prefix : impl FnOnce ( Self ) -> Result < Self :: Path , Self :: Error > ,
180182 disambiguated_data : & DisambiguatedDefPathData ,
181183 ) -> Result < Self :: Path , Self :: Error > {
182184 let mut path = print_prefix ( self ) ?;
183- path. push ( disambiguated_data. data . as_interned_str ( ) . to_string ( ) ) ;
185+ path. push ( disambiguated_data. data . as_interned_str ( ) . as_str ( ) ) ;
184186 Ok ( path)
185187 }
188+
186189 fn path_generic_args (
187190 self ,
188191 print_prefix : impl FnOnce ( Self ) -> Result < Self :: Path , Self :: Error > ,
@@ -215,8 +218,8 @@ pub fn match_def_path<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, path
215218/// // The given `def_id` is that of an `Option` type
216219/// };
217220/// ```
218- pub fn get_def_path < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> Vec < String > {
219- AbsolutePathPrinter { tcx } . print_def_path ( def_id, & [ ] ) . unwrap ( )
221+ pub fn get_def_path < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , def_id : DefId ) -> Vec < & ' static str > {
222+ AbsolutePathPrinter { tcx } . print_def_path ( def_id, & [ ] ) . unwrap ( ) . iter ( ) . map ( LocalInternedString :: get ) . collect ( )
220223}
221224
222225/// Checks if type is struct, enum or union type with the given def path.
0 commit comments