11use std:: assert_matches:: assert_matches;
22use std:: fmt;
3- use std:: path:: PathBuf ;
43
54use rustc_data_structures:: fx:: FxHashMap ;
65use rustc_errors:: ErrorGuaranteed ;
@@ -17,7 +16,7 @@ use tracing::{debug, instrument};
1716use crate :: error;
1817use crate :: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
1918use crate :: ty:: normalize_erasing_regions:: NormalizationError ;
20- use crate :: ty:: print:: { FmtPrinter , Printer , shrunk_instance_name } ;
19+ use crate :: ty:: print:: { FmtPrinter , Print } ;
2120use crate :: ty:: {
2221 self , EarlyBinder , GenericArgs , GenericArgsRef , Ty , TyCtxt , TypeFoldable , TypeSuperVisitable ,
2322 TypeVisitable , TypeVisitableExt , TypeVisitor ,
@@ -389,59 +388,15 @@ fn type_length<'tcx>(item: impl TypeVisitable<TyCtxt<'tcx>>) -> usize {
389388 visitor. type_length
390389}
391390
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-
442391impl < ' tcx > fmt:: Display for Instance < ' tcx > {
443392 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+ } )
445400 }
446401}
447402
@@ -610,23 +565,12 @@ impl<'tcx> Instance<'tcx> {
610565 Ok ( None ) => {
611566 let type_length = type_length ( args) ;
612567 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- } ;
622568 tcx. dcx ( ) . emit_fatal ( error:: TypeLengthLimit {
623569 // We don't use `def_span(def_id)` so that diagnostics point
624570 // to the crate root during mono instead of to foreign items.
625571 // This is arguably better.
626572 span : span_or_local_def_span ( ) ,
627- shrunk,
628- was_written,
629- path,
573+ instance : Instance :: new_raw ( def_id, args) ,
630574 type_length,
631575 } ) ;
632576 } else {
0 commit comments