1- use std:: path:: PathBuf ;
2-
31use hir:: def:: Namespace ;
42use rustc_data_structures:: fx:: FxHashSet ;
53use rustc_data_structures:: sso:: SsoHashSet ;
@@ -8,7 +6,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
86use rustc_hir:: definitions:: { DefPathData , DisambiguatedDefPathData } ;
97use tracing:: { debug, instrument, trace} ;
108
11- use crate :: ty:: { self , GenericArg , ShortInstance , Ty , TyCtxt } ;
9+ use crate :: ty:: { self , GenericArg , Ty , TyCtxt } ;
1210
1311// `pretty` is a separate module only for organization.
1412mod pretty;
@@ -323,6 +321,43 @@ impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for Ty<'tcx> {
323321 }
324322}
325323
324+ impl < ' tcx , P : Printer < ' tcx > + std:: fmt:: Write > Print < ' tcx , P > for ty:: Instance < ' tcx > {
325+ fn print ( & self , cx : & mut P ) -> Result < ( ) , PrintError > {
326+ cx. print_def_path ( self . def_id ( ) , self . args ) ?;
327+ match self . def {
328+ ty:: InstanceKind :: Item ( _) => { }
329+ ty:: InstanceKind :: VTableShim ( _) => cx. write_str ( " - shim(vtable)" ) ?,
330+ ty:: InstanceKind :: ReifyShim ( _, None ) => cx. write_str ( " - shim(reify)" ) ?,
331+ ty:: InstanceKind :: ReifyShim ( _, Some ( ty:: ReifyReason :: FnPtr ) ) => {
332+ cx. write_str ( " - shim(reify-fnptr)" ) ?
333+ }
334+ ty:: InstanceKind :: ReifyShim ( _, Some ( ty:: ReifyReason :: Vtable ) ) => {
335+ cx. write_str ( " - shim(reify-vtable)" ) ?
336+ }
337+ ty:: InstanceKind :: ThreadLocalShim ( _) => cx. write_str ( " - shim(tls)" ) ?,
338+ ty:: InstanceKind :: Intrinsic ( _) => cx. write_str ( " - intrinsic" ) ?,
339+ ty:: InstanceKind :: Virtual ( _, num) => cx. write_str ( & format ! ( " - virtual#{num}" ) ) ?,
340+ ty:: InstanceKind :: FnPtrShim ( _, ty) => cx. write_str ( & format ! ( " - shim({ty})" ) ) ?,
341+ ty:: InstanceKind :: ClosureOnceShim { .. } => cx. write_str ( " - shim" ) ?,
342+ ty:: InstanceKind :: ConstructCoroutineInClosureShim { .. } => cx. write_str ( " - shim" ) ?,
343+ ty:: InstanceKind :: DropGlue ( _, None ) => cx. write_str ( " - shim(None)" ) ?,
344+ ty:: InstanceKind :: DropGlue ( _, Some ( ty) ) => {
345+ cx. write_str ( & format ! ( " - shim(Some({ty}))" ) ) ?
346+ }
347+ ty:: InstanceKind :: CloneShim ( _, ty) => cx. write_str ( & format ! ( " - shim({ty})" ) ) ?,
348+ ty:: InstanceKind :: FnPtrAddrShim ( _, ty) => cx. write_str ( & format ! ( " - shim({ty})" ) ) ?,
349+ ty:: InstanceKind :: FutureDropPollShim ( _, proxy_ty, impl_ty) => {
350+ cx. write_str ( & format ! ( " - dropshim({proxy_ty}-{impl_ty})" ) ) ?
351+ }
352+ ty:: InstanceKind :: AsyncDropGlue ( _, ty) => cx. write_str ( & format ! ( " - shim({ty})" ) ) ?,
353+ ty:: InstanceKind :: AsyncDropGlueCtorShim ( _, ty) => {
354+ cx. write_str ( & format ! ( " - shim(Some({ty}))" ) ) ?
355+ }
356+ } ;
357+ Ok ( ( ) )
358+ }
359+ }
360+
326361impl < ' tcx , P : Printer < ' tcx > > Print < ' tcx , P > for & ' tcx ty:: List < ty:: PolyExistentialPredicate < ' tcx > > {
327362 fn print ( & self , cx : & mut P ) -> Result < ( ) , PrintError > {
328363 cx. print_dyn_existential ( self )
@@ -362,31 +397,3 @@ where
362397 with_no_trimmed_paths ! ( Self :: print( t, fmt) )
363398 }
364399}
365-
366- /// Format instance name that is already known to be too long for rustc.
367- /// Show only the first 2 types if it is longer than 32 characters to avoid blasting
368- /// the user's terminal with thousands of lines of type-name.
369- ///
370- /// If the type name is longer than before+after, it will be written to a file.
371- pub fn shrunk_instance_name < ' tcx > (
372- tcx : TyCtxt < ' tcx > ,
373- instance : ty:: Instance < ' tcx > ,
374- ) -> ( String , Option < PathBuf > ) {
375- let s = instance. to_string ( ) ;
376-
377- // Only use the shrunk version if it's really shorter.
378- // This also avoids the case where before and after slices overlap.
379- if s. chars ( ) . nth ( 33 ) . is_some ( ) {
380- let shrunk = format ! ( "{}" , ShortInstance ( instance, 4 ) ) ;
381- if shrunk == s {
382- return ( s, None ) ;
383- }
384-
385- let path = tcx. output_filenames ( ( ) ) . temp_path_for_diagnostic ( "long-type.txt" ) ;
386- let written_to_path = std:: fs:: write ( & path, s) . ok ( ) . map ( |_| path) ;
387-
388- ( shrunk, written_to_path)
389- } else {
390- ( s, None )
391- }
392- }
0 commit comments