1
1
use std:: assert_matches:: assert_matches;
2
2
use std:: fmt;
3
- use std:: path:: PathBuf ;
4
3
5
4
use rustc_data_structures:: fx:: FxHashMap ;
6
5
use rustc_errors:: ErrorGuaranteed ;
@@ -17,7 +16,7 @@ use tracing::{debug, instrument};
17
16
use crate :: error;
18
17
use crate :: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
19
18
use crate :: ty:: normalize_erasing_regions:: NormalizationError ;
20
- use crate :: ty:: print:: { FmtPrinter , Printer , shrunk_instance_name } ;
19
+ use crate :: ty:: print:: { FmtPrinter , Print } ;
21
20
use crate :: ty:: {
22
21
self , EarlyBinder , GenericArgs , GenericArgsRef , Ty , TyCtxt , TypeFoldable , TypeSuperVisitable ,
23
22
TypeVisitable , TypeVisitableExt , TypeVisitor ,
@@ -389,59 +388,15 @@ fn type_length<'tcx>(item: impl TypeVisitable<TyCtxt<'tcx>>) -> usize {
389
388
visitor. type_length
390
389
}
391
390
392
- pub fn fmt_instance (
393
- f : & mut fmt:: Formatter < ' _ > ,
394
- instance : Instance < ' _ > ,
395
- type_length : Option < rustc_session:: Limit > ,
396
- ) -> fmt:: Result {
397
- ty:: tls:: with ( |tcx| {
398
- let args = tcx. lift ( instance. args ) . expect ( "could not lift for printing" ) ;
399
-
400
- let mut p = if let Some ( type_length) = type_length {
401
- FmtPrinter :: new_with_limit ( tcx, Namespace :: ValueNS , type_length)
402
- } else {
403
- FmtPrinter :: new ( tcx, Namespace :: ValueNS )
404
- } ;
405
- p. print_def_path ( instance. def_id ( ) , args) ?;
406
- let s = p. into_buffer ( ) ;
407
- f. write_str ( & s)
408
- } ) ?;
409
-
410
- match instance. def {
411
- InstanceKind :: Item ( _) => Ok ( ( ) ) ,
412
- InstanceKind :: VTableShim ( _) => write ! ( f, " - shim(vtable)" ) ,
413
- InstanceKind :: ReifyShim ( _, None ) => write ! ( f, " - shim(reify)" ) ,
414
- InstanceKind :: ReifyShim ( _, Some ( ReifyReason :: FnPtr ) ) => write ! ( f, " - shim(reify-fnptr)" ) ,
415
- InstanceKind :: ReifyShim ( _, Some ( ReifyReason :: Vtable ) ) => write ! ( f, " - shim(reify-vtable)" ) ,
416
- InstanceKind :: ThreadLocalShim ( _) => write ! ( f, " - shim(tls)" ) ,
417
- InstanceKind :: Intrinsic ( _) => write ! ( f, " - intrinsic" ) ,
418
- InstanceKind :: Virtual ( _, num) => write ! ( f, " - virtual#{num}" ) ,
419
- InstanceKind :: FnPtrShim ( _, ty) => write ! ( f, " - shim({ty})" ) ,
420
- InstanceKind :: ClosureOnceShim { .. } => write ! ( f, " - shim" ) ,
421
- InstanceKind :: ConstructCoroutineInClosureShim { .. } => write ! ( f, " - shim" ) ,
422
- InstanceKind :: DropGlue ( _, None ) => write ! ( f, " - shim(None)" ) ,
423
- InstanceKind :: DropGlue ( _, Some ( ty) ) => write ! ( f, " - shim(Some({ty}))" ) ,
424
- InstanceKind :: CloneShim ( _, ty) => write ! ( f, " - shim({ty})" ) ,
425
- InstanceKind :: FnPtrAddrShim ( _, ty) => write ! ( f, " - shim({ty})" ) ,
426
- InstanceKind :: FutureDropPollShim ( _, proxy_ty, impl_ty) => {
427
- write ! ( f, " - dropshim({proxy_ty}-{impl_ty})" )
428
- }
429
- InstanceKind :: AsyncDropGlue ( _, ty) => write ! ( f, " - shim({ty})" ) ,
430
- InstanceKind :: AsyncDropGlueCtorShim ( _, ty) => write ! ( f, " - shim(Some({ty}))" ) ,
431
- }
432
- }
433
-
434
- pub struct ShortInstance < ' tcx > ( pub Instance < ' tcx > , pub usize ) ;
435
-
436
- impl < ' tcx > fmt:: Display for ShortInstance < ' tcx > {
437
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
438
- fmt_instance ( f, self . 0 , Some ( rustc_session:: Limit ( self . 1 ) ) )
439
- }
440
- }
441
-
442
391
impl < ' tcx > fmt:: Display for Instance < ' tcx > {
443
392
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
444
- fmt_instance ( f, * self , None )
393
+ ty:: tls:: with ( |tcx| {
394
+ let mut p = FmtPrinter :: new ( tcx, Namespace :: ValueNS ) ;
395
+ let instance = tcx. lift ( * self ) . expect ( "could not lift for printing" ) ;
396
+ instance. print ( & mut p) ?;
397
+ let s = p. into_buffer ( ) ;
398
+ f. write_str ( & s)
399
+ } )
445
400
}
446
401
}
447
402
@@ -610,23 +565,12 @@ impl<'tcx> Instance<'tcx> {
610
565
Ok ( None ) => {
611
566
let type_length = type_length ( args) ;
612
567
if !tcx. type_length_limit ( ) . value_within_limit ( type_length) {
613
- let ( shrunk, written_to_path) =
614
- shrunk_instance_name ( tcx, Instance :: new_raw ( def_id, args) ) ;
615
- let mut path = PathBuf :: new ( ) ;
616
- let was_written = if let Some ( path2) = written_to_path {
617
- path = path2;
618
- true
619
- } else {
620
- false
621
- } ;
622
568
tcx. dcx ( ) . emit_fatal ( error:: TypeLengthLimit {
623
569
// We don't use `def_span(def_id)` so that diagnostics point
624
570
// to the crate root during mono instead of to foreign items.
625
571
// This is arguably better.
626
572
span : span_or_local_def_span ( ) ,
627
- shrunk,
628
- was_written,
629
- path,
573
+ instance : Instance :: new_raw ( def_id, args) ,
630
574
type_length,
631
575
} ) ;
632
576
} else {
0 commit comments