@@ -276,28 +276,45 @@ impl<'tcx> InstanceDef<'tcx> {
276
276
}
277
277
}
278
278
279
- impl < ' tcx > fmt:: Display for Instance < ' tcx > {
279
+ fn fmt_instance (
280
+ f : & mut fmt:: Formatter < ' _ > ,
281
+ instance : & Instance < ' _ > ,
282
+ type_length : rustc_session:: Limit ,
283
+ ) -> fmt:: Result {
284
+ ty:: tls:: with ( |tcx| {
285
+ let substs = tcx. lift ( instance. substs ) . expect ( "could not lift for printing" ) ;
286
+
287
+ let s = FmtPrinter :: new_with_limit ( tcx, Namespace :: ValueNS , type_length)
288
+ . print_def_path ( instance. def_id ( ) , substs) ?
289
+ . into_buffer ( ) ;
290
+ f. write_str ( & s)
291
+ } ) ?;
292
+
293
+ match instance. def {
294
+ InstanceDef :: Item ( _) => Ok ( ( ) ) ,
295
+ InstanceDef :: VTableShim ( _) => write ! ( f, " - shim(vtable)" ) ,
296
+ InstanceDef :: ReifyShim ( _) => write ! ( f, " - shim(reify)" ) ,
297
+ InstanceDef :: Intrinsic ( _) => write ! ( f, " - intrinsic" ) ,
298
+ InstanceDef :: Virtual ( _, num) => write ! ( f, " - virtual#{}" , num) ,
299
+ InstanceDef :: FnPtrShim ( _, ty) => write ! ( f, " - shim({})" , ty) ,
300
+ InstanceDef :: ClosureOnceShim { .. } => write ! ( f, " - shim" ) ,
301
+ InstanceDef :: DropGlue ( _, None ) => write ! ( f, " - shim(None)" ) ,
302
+ InstanceDef :: DropGlue ( _, Some ( ty) ) => write ! ( f, " - shim(Some({}))" , ty) ,
303
+ InstanceDef :: CloneShim ( _, ty) => write ! ( f, " - shim({})" , ty) ,
304
+ }
305
+ }
306
+
307
+ pub struct ShortInstance < ' a , ' tcx > ( pub & ' a Instance < ' tcx > , pub usize ) ;
308
+
309
+ impl < ' a , ' tcx > fmt:: Display for ShortInstance < ' a , ' tcx > {
280
310
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
281
- ty:: tls:: with ( |tcx| {
282
- let substs = tcx. lift ( self . substs ) . expect ( "could not lift for printing" ) ;
283
- let s = FmtPrinter :: new ( tcx, Namespace :: ValueNS )
284
- . print_def_path ( self . def_id ( ) , substs) ?
285
- . into_buffer ( ) ;
286
- f. write_str ( & s)
287
- } ) ?;
311
+ fmt_instance ( f, self . 0 , rustc_session:: Limit ( self . 1 ) )
312
+ }
313
+ }
288
314
289
- match self . def {
290
- InstanceDef :: Item ( _) => Ok ( ( ) ) ,
291
- InstanceDef :: VTableShim ( _) => write ! ( f, " - shim(vtable)" ) ,
292
- InstanceDef :: ReifyShim ( _) => write ! ( f, " - shim(reify)" ) ,
293
- InstanceDef :: Intrinsic ( _) => write ! ( f, " - intrinsic" ) ,
294
- InstanceDef :: Virtual ( _, num) => write ! ( f, " - virtual#{}" , num) ,
295
- InstanceDef :: FnPtrShim ( _, ty) => write ! ( f, " - shim({})" , ty) ,
296
- InstanceDef :: ClosureOnceShim { .. } => write ! ( f, " - shim" ) ,
297
- InstanceDef :: DropGlue ( _, None ) => write ! ( f, " - shim(None)" ) ,
298
- InstanceDef :: DropGlue ( _, Some ( ty) ) => write ! ( f, " - shim(Some({}))" , ty) ,
299
- InstanceDef :: CloneShim ( _, ty) => write ! ( f, " - shim({})" , ty) ,
300
- }
315
+ impl < ' tcx > fmt:: Display for Instance < ' tcx > {
316
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
317
+ ty:: tls:: with ( |tcx| fmt_instance ( f, self , tcx. type_length_limit ( ) ) )
301
318
}
302
319
}
303
320
0 commit comments