@@ -160,7 +160,11 @@ impl<'tcx> Ty<'tcx> {
160
160
_ => {
161
161
let width = tcx. sess . diagnostic_width ( ) ;
162
162
let length_limit = std:: cmp:: max ( width / 4 , 40 ) ;
163
- format ! ( "`{}`" , tcx. string_with_limit( self , length_limit) ) . into ( )
163
+ format ! (
164
+ "`{}`" ,
165
+ tcx. string_with_limit( self , length_limit, hir:: def:: Namespace :: TypeNS )
166
+ )
167
+ . into ( )
164
168
}
165
169
}
166
170
}
@@ -213,12 +217,12 @@ impl<'tcx> Ty<'tcx> {
213
217
}
214
218
215
219
impl < ' tcx > TyCtxt < ' tcx > {
216
- pub fn string_with_limit < T > ( self , p : T , length_limit : usize ) -> String
220
+ pub fn string_with_limit < T > ( self , p : T , length_limit : usize , ns : hir :: def :: Namespace ) -> String
217
221
where
218
222
T : Copy + for < ' a , ' b > Lift < TyCtxt < ' b > , Lifted : Print < ' b , FmtPrinter < ' a , ' b > > > ,
219
223
{
220
224
let mut type_limit = 50 ;
221
- let regular = FmtPrinter :: print_string ( self , hir :: def :: Namespace :: TypeNS , |cx| {
225
+ let regular = FmtPrinter :: print_string ( self , ns , |cx| {
222
226
self . lift ( p) . expect ( "could not lift for printing" ) . print ( cx)
223
227
} )
224
228
. expect ( "could not write to `String`" ) ;
@@ -229,11 +233,7 @@ impl<'tcx> TyCtxt<'tcx> {
229
233
loop {
230
234
// Look for the longest properly trimmed path that still fits in length_limit.
231
235
short = with_forced_trimmed_paths ! ( {
232
- let mut cx = FmtPrinter :: new_with_limit(
233
- self ,
234
- hir:: def:: Namespace :: TypeNS ,
235
- rustc_session:: Limit ( type_limit) ,
236
- ) ;
236
+ let mut cx = FmtPrinter :: new_with_limit( self , ns, rustc_session:: Limit ( type_limit) ) ;
237
237
self . lift( p)
238
238
. expect( "could not lift for printing" )
239
239
. print( & mut cx)
@@ -248,15 +248,27 @@ impl<'tcx> TyCtxt<'tcx> {
248
248
short
249
249
}
250
250
251
+ pub fn short_string < T > ( self , p : T , path : & mut Option < PathBuf > ) -> String
252
+ where
253
+ T : Copy + Hash + for < ' a , ' b > Lift < TyCtxt < ' b > , Lifted : Print < ' b , FmtPrinter < ' a , ' b > > > ,
254
+ {
255
+ self . short_string_namespace ( p, path, hir:: def:: Namespace :: TypeNS )
256
+ }
257
+
251
258
/// When calling this after a `Diag` is constructed, the preferred way of doing so is
252
259
/// `tcx.short_string(ty, diag.long_ty_path())`. The diagnostic itself is the one that keeps
253
260
/// the existence of a "long type" anywhere in the diagnostic, so the note telling the user
254
261
/// where we wrote the file to is only printed once.
255
- pub fn short_string < T > ( self , p : T , path : & mut Option < PathBuf > ) -> String
262
+ pub fn short_string_namespace < T > (
263
+ self ,
264
+ p : T ,
265
+ path : & mut Option < PathBuf > ,
266
+ namespace : hir:: def:: Namespace ,
267
+ ) -> String
256
268
where
257
269
T : Copy + Hash + for < ' a , ' b > Lift < TyCtxt < ' b > , Lifted : Print < ' b , FmtPrinter < ' a , ' b > > > ,
258
270
{
259
- let regular = FmtPrinter :: print_string ( self , hir :: def :: Namespace :: TypeNS , |cx| {
271
+ let regular = FmtPrinter :: print_string ( self , namespace , |cx| {
260
272
self . lift ( p) . expect ( "could not lift for printing" ) . print ( cx)
261
273
} )
262
274
. expect ( "could not write to `String`" ) ;
@@ -270,7 +282,7 @@ impl<'tcx> TyCtxt<'tcx> {
270
282
if regular. len ( ) <= width * 2 / 3 {
271
283
return regular;
272
284
}
273
- let short = self . string_with_limit ( p, length_limit) ;
285
+ let short = self . string_with_limit ( p, length_limit, namespace ) ;
274
286
if regular == short {
275
287
return regular;
276
288
}
0 commit comments