33use  std:: assert_matches:: debug_assert_matches; 
44use  std:: borrow:: Cow ; 
55use  std:: iter; 
6+ use  std:: path:: PathBuf ; 
67
78use  itertools:: { EitherOrBoth ,  Itertools } ; 
89use  rustc_data_structures:: fx:: FxHashSet ; 
@@ -2703,6 +2704,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
27032704        // Add a note for the item obligation that remains - normally a note pointing to the 
27042705        // bound that introduced the obligation (e.g. `T: Send`). 
27052706        debug ! ( ?next_code) ; 
2707+         let  mut  long_ty_file = None ; 
27062708        self . note_obligation_cause_code ( 
27072709            obligation. cause . body_id , 
27082710            err, 
@@ -2711,6 +2713,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
27112713            next_code. unwrap ( ) , 
27122714            & mut  Vec :: new ( ) , 
27132715            & mut  Default :: default ( ) , 
2716+             & mut  long_ty_file, 
27142717        ) ; 
27152718    } 
27162719
@@ -2723,11 +2726,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
27232726        cause_code :  & ObligationCauseCode < ' tcx > , 
27242727        obligated_types :  & mut  Vec < Ty < ' tcx > > , 
27252728        seen_requirements :  & mut  FxHashSet < DefId > , 
2729+         long_ty_file :  & mut  Option < PathBuf > , 
27262730    )  where 
27272731        T :  Upcast < TyCtxt < ' tcx > ,  ty:: Predicate < ' tcx > > , 
27282732    { 
2729-         let  mut  long_ty_file = None ; 
2730- 
27312733        let  tcx = self . tcx ; 
27322734        let  predicate = predicate. upcast ( tcx) ; 
27332735        let  suggest_remove_deref = |err :  & mut  Diag < ' _ ,  G > ,  expr :  & hir:: Expr < ' _ > | { 
@@ -2957,9 +2959,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
29572959            } 
29582960            ObligationCauseCode :: Coercion  {  source,  target }  => { 
29592961                let  source =
2960-                     tcx. short_ty_string ( self . resolve_vars_if_possible ( source) ,  & mut   long_ty_file) ; 
2962+                     tcx. short_ty_string ( self . resolve_vars_if_possible ( source) ,  long_ty_file) ; 
29612963                let  target =
2962-                     tcx. short_ty_string ( self . resolve_vars_if_possible ( target) ,  & mut   long_ty_file) ; 
2964+                     tcx. short_ty_string ( self . resolve_vars_if_possible ( target) ,  long_ty_file) ; 
29632965                err. note ( with_forced_trimmed_paths ! ( format!( 
29642966                    "required for the cast from `{source}` to `{target}`" , 
29652967                ) ) ) ; 
@@ -3249,7 +3251,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
32493251                } ; 
32503252
32513253                if  !is_upvar_tys_infer_tuple { 
3252-                     let  ty_str = tcx. short_ty_string ( ty,  & mut   long_ty_file) ; 
3254+                     let  ty_str = tcx. short_ty_string ( ty,  long_ty_file) ; 
32533255                    let  msg = format ! ( "required because it appears within the type `{ty_str}`" ) ; 
32543256                    match  ty. kind ( )  { 
32553257                        ty:: Adt ( def,  _)  => match  tcx. opt_item_ident ( def. did ( ) )  { 
@@ -3327,6 +3329,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
33273329                            & data. parent_code , 
33283330                            obligated_types, 
33293331                            seen_requirements, 
3332+                             long_ty_file, 
33303333                        ) 
33313334                    } ) ; 
33323335                }  else  { 
@@ -3339,6 +3342,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
33393342                            cause_code. peel_derives ( ) , 
33403343                            obligated_types, 
33413344                            seen_requirements, 
3345+                             long_ty_file, 
33423346                        ) 
33433347                    } ) ; 
33443348                } 
@@ -3347,8 +3351,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
33473351                let  mut  parent_trait_pred =
33483352                    self . resolve_vars_if_possible ( data. derived . parent_trait_pred ) ; 
33493353                let  parent_def_id = parent_trait_pred. def_id ( ) ; 
3350-                 let  self_ty_str = tcx 
3351-                     . short_ty_string ( parent_trait_pred. skip_binder ( ) . self_ty ( ) ,   & mut  long_ty_file) ; 
3354+                 let  self_ty_str =
3355+                     tcx . short_ty_string ( parent_trait_pred. skip_binder ( ) . self_ty ( ) ,  long_ty_file) ; 
33523356                let  trait_name = parent_trait_pred. print_modifiers_and_trait_path ( ) . to_string ( ) ; 
33533357                let  msg = format ! ( "required for `{self_ty_str}` to implement `{trait_name}`" ) ; 
33543358                let  mut  is_auto_trait = false ; 
@@ -3444,10 +3448,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
34443448                        count, 
34453449                        pluralize!( count) 
34463450                    ) ) ; 
3447-                     let  self_ty = tcx. short_ty_string ( 
3448-                         parent_trait_pred. skip_binder ( ) . self_ty ( ) , 
3449-                         & mut  long_ty_file, 
3450-                     ) ; 
3451+                     let  self_ty = tcx
3452+                         . short_ty_string ( parent_trait_pred. skip_binder ( ) . self_ty ( ) ,  long_ty_file) ; 
34513453                    err. note ( format ! ( 
34523454                        "required for `{self_ty}` to implement `{}`" , 
34533455                        parent_trait_pred. print_modifiers_and_trait_path( ) 
@@ -3463,6 +3465,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
34633465                        & data. parent_code , 
34643466                        obligated_types, 
34653467                        seen_requirements, 
3468+                         long_ty_file, 
34663469                    ) 
34673470                } ) ; 
34683471            } 
@@ -3479,6 +3482,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
34793482                        & data. parent_code , 
34803483                        obligated_types, 
34813484                        seen_requirements, 
3485+                         long_ty_file, 
34823486                    ) 
34833487                } ) ; 
34843488            } 
@@ -3493,6 +3497,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
34933497                        nested, 
34943498                        obligated_types, 
34953499                        seen_requirements, 
3500+                         long_ty_file, 
34963501                    ) 
34973502                } ) ; 
34983503                let  mut  multispan = MultiSpan :: from ( span) ; 
@@ -3523,6 +3528,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
35233528                        parent_code, 
35243529                        obligated_types, 
35253530                        seen_requirements, 
3531+                         long_ty_file, 
35263532                    ) 
35273533                } ) ; 
35283534            } 
@@ -3562,7 +3568,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
35623568            } 
35633569            ObligationCauseCode :: OpaqueReturnType ( expr_info)  => { 
35643570                if  let  Some ( ( expr_ty,  hir_id) )  = expr_info { 
3565-                     let  expr_ty = self . tcx . short_ty_string ( expr_ty,  & mut   long_ty_file) ; 
3571+                     let  expr_ty = self . tcx . short_ty_string ( expr_ty,  long_ty_file) ; 
35663572                    let  expr = self . infcx . tcx . hir ( ) . expect_expr ( hir_id) ; 
35673573                    err. span_label ( 
35683574                        expr. span , 
@@ -3574,14 +3580,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
35743580                } 
35753581            } 
35763582        } 
3577- 
3578-         if  let  Some ( file)  = long_ty_file { 
3579-             err. note ( format ! ( 
3580-                 "the full name for the type has been written to '{}'" , 
3581-                 file. display( ) , 
3582-             ) ) ; 
3583-             err. note ( "consider using `--verbose` to print the full type name to the console" ) ; 
3584-         } 
35853583    } 
35863584
35873585    #[ instrument(  
0 commit comments