@@ -43,7 +43,7 @@ use rustc_errors::Applicability;
43
43
use syntax:: ast:: { self , LitKind } ;
44
44
use syntax:: attr;
45
45
use syntax:: source_map:: { Span , DUMMY_SP } ;
46
- use syntax:: symbol:: { keywords, Symbol } ;
46
+ use syntax:: symbol:: { keywords, Symbol , LocalInternedString } ;
47
47
48
48
use crate :: reexport:: * ;
49
49
@@ -107,7 +107,7 @@ use rustc::ty::print::Printer;
107
107
impl < ' tcx > Printer < ' tcx , ' tcx > for AbsolutePathPrinter < ' _ , ' tcx > {
108
108
type Error = !;
109
109
110
- type Path = Vec < String > ;
110
+ type Path = Vec < LocalInternedString > ;
111
111
type Region = ( ) ;
112
112
type Type = ( ) ;
113
113
type DynExistential = ( ) ;
@@ -141,17 +141,18 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
141
141
self ,
142
142
cnum : CrateNum ,
143
143
) -> 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 ( ) ] )
145
145
}
146
+
146
147
fn path_qualified (
147
148
self ,
148
149
self_ty : Ty < ' tcx > ,
149
150
trait_ref : Option < ty:: TraitRef < ' tcx > > ,
150
151
) -> Result < Self :: Path , Self :: Error > {
151
152
// This shouldn't ever be needed, but just in case:
152
153
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 ( ) ,
155
156
} ] )
156
157
}
157
158
@@ -167,22 +168,24 @@ impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
167
168
// This shouldn't ever be needed, but just in case:
168
169
path. push ( match trait_ref {
169
170
Some ( trait_ref) => {
170
- format ! ( "<impl {} for {}>" , trait_ref, self_ty)
171
+ Symbol :: intern ( & format ! ( "<impl {} for {}>" , trait_ref, self_ty) ) . as_str ( )
171
172
}
172
- None => format ! ( "<impl {}>" , self_ty) ,
173
+ None => Symbol :: intern ( & format ! ( "<impl {}>" , self_ty) ) . as_str ( ) ,
173
174
} ) ;
174
175
175
176
Ok ( path)
176
177
}
178
+
177
179
fn path_append (
178
180
self ,
179
181
print_prefix : impl FnOnce ( Self ) -> Result < Self :: Path , Self :: Error > ,
180
182
disambiguated_data : & DisambiguatedDefPathData ,
181
183
) -> Result < Self :: Path , Self :: Error > {
182
184
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 ( ) ) ;
184
186
Ok ( path)
185
187
}
188
+
186
189
fn path_generic_args (
187
190
self ,
188
191
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
215
218
/// // The given `def_id` is that of an `Option` type
216
219
/// };
217
220
/// ```
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 ( )
220
223
}
221
224
222
225
/// Checks if type is struct, enum or union type with the given def path.
0 commit comments