@@ -2676,6 +2676,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
26762676 ) where
26772677 T : ToPredicate < ' tcx > ,
26782678 {
2679+ let mut long_ty_file = None ;
2680+
26792681 let tcx = self . tcx ;
26802682 let predicate = predicate. to_predicate ( tcx) ;
26812683 match * cause_code {
@@ -2858,21 +2860,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
28582860 }
28592861 }
28602862 ObligationCauseCode :: Coercion { source, target } => {
2861- let mut file = None ;
2862- let source = tcx. short_ty_string ( self . resolve_vars_if_possible ( source) , & mut file) ;
2863- let target = tcx. short_ty_string ( self . resolve_vars_if_possible ( target) , & mut file) ;
2863+ let source =
2864+ tcx. short_ty_string ( self . resolve_vars_if_possible ( source) , & mut long_ty_file) ;
2865+ let target =
2866+ tcx. short_ty_string ( self . resolve_vars_if_possible ( target) , & mut long_ty_file) ;
28642867 err. note ( with_forced_trimmed_paths ! ( format!(
28652868 "required for the cast from `{source}` to `{target}`" ,
28662869 ) ) ) ;
2867- if let Some ( file) = file {
2868- err. note ( format ! (
2869- "the full name for the type has been written to '{}'" ,
2870- file. display( ) ,
2871- ) ) ;
2872- err. note (
2873- "consider using `--verbose` to print the full type name to the console" ,
2874- ) ;
2875- }
28762870 }
28772871 ObligationCauseCode :: RepeatElementCopy {
28782872 is_constable,
@@ -3175,8 +3169,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
31753169 // Don't print the tuple of capture types
31763170 ' print: {
31773171 if !is_upvar_tys_infer_tuple {
3178- let mut file = None ;
3179- let ty_str = tcx. short_ty_string ( ty, & mut file) ;
3172+ let ty_str = tcx. short_ty_string ( ty, & mut long_ty_file) ;
31803173 let msg = format ! ( "required because it appears within the type `{ty_str}`" ) ;
31813174 match ty. kind ( ) {
31823175 ty:: Adt ( def, _) => match tcx. opt_item_ident ( def. did ( ) ) {
@@ -3274,9 +3267,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
32743267 let mut parent_trait_pred =
32753268 self . resolve_vars_if_possible ( data. derived . parent_trait_pred ) ;
32763269 let parent_def_id = parent_trait_pred. def_id ( ) ;
3277- let mut file = None ;
3278- let self_ty_str =
3279- tcx. short_ty_string ( parent_trait_pred. skip_binder ( ) . self_ty ( ) , & mut file) ;
3270+ let self_ty_str = tcx
3271+ . short_ty_string ( parent_trait_pred. skip_binder ( ) . self_ty ( ) , & mut long_ty_file) ;
32803272 let trait_name = parent_trait_pred. print_modifiers_and_trait_path ( ) . to_string ( ) ;
32813273 let msg = format ! ( "required for `{self_ty_str}` to implement `{trait_name}`" ) ;
32823274 let mut is_auto_trait = false ;
@@ -3334,15 +3326,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
33343326 }
33353327 } ;
33363328
3337- if let Some ( file) = file {
3338- err. note ( format ! (
3339- "the full type name has been written to '{}'" ,
3340- file. display( ) ,
3341- ) ) ;
3342- err. note (
3343- "consider using `--verbose` to print the full type name to the console" ,
3344- ) ;
3345- }
33463329 let mut parent_predicate = parent_trait_pred;
33473330 let mut data = & data. derived ;
33483331 let mut count = 0 ;
@@ -3383,22 +3366,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
33833366 count,
33843367 pluralize!( count)
33853368 ) ) ;
3386- let mut file = None ;
3387- let self_ty =
3388- tcx. short_ty_string ( parent_trait_pred. skip_binder ( ) . self_ty ( ) , & mut file) ;
3369+ let self_ty = tcx. short_ty_string (
3370+ parent_trait_pred. skip_binder ( ) . self_ty ( ) ,
3371+ & mut long_ty_file,
3372+ ) ;
33893373 err. note ( format ! (
33903374 "required for `{self_ty}` to implement `{}`" ,
33913375 parent_trait_pred. print_modifiers_and_trait_path( )
33923376 ) ) ;
3393- if let Some ( file) = file {
3394- err. note ( format ! (
3395- "the full type name has been written to '{}'" ,
3396- file. display( ) ,
3397- ) ) ;
3398- err. note (
3399- "consider using `--verbose` to print the full type name to the console" ,
3400- ) ;
3401- }
34023377 }
34033378 // #74711: avoid a stack overflow
34043379 ensure_sufficient_stack ( || {
@@ -3507,8 +3482,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
35073482 }
35083483 ObligationCauseCode :: OpaqueReturnType ( expr_info) => {
35093484 if let Some ( ( expr_ty, expr_span) ) = expr_info {
3510- let expr_ty =
3511- with_forced_trimmed_paths ! ( self . tcx. short_ty_string( expr_ty, & mut None ) ) ;
3485+ let expr_ty = self . tcx . short_ty_string ( expr_ty, & mut long_ty_file) ;
35123486 err. span_label (
35133487 expr_span,
35143488 with_forced_trimmed_paths ! ( format!(
@@ -3518,6 +3492,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
35183492 }
35193493 }
35203494 }
3495+
3496+ if let Some ( file) = long_ty_file {
3497+ err. note ( format ! (
3498+ "the full name for the type has been written to '{}'" ,
3499+ file. display( ) ,
3500+ ) ) ;
3501+ err. note ( "consider using `--verbose` to print the full type name to the console" ) ;
3502+ }
35213503 }
35223504
35233505 #[ instrument(
0 commit comments