@@ -2676,6 +2676,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2676
2676
) where
2677
2677
T : ToPredicate < ' tcx > ,
2678
2678
{
2679
+ let mut long_ty_file = None ;
2680
+
2679
2681
let tcx = self . tcx ;
2680
2682
let predicate = predicate. to_predicate ( tcx) ;
2681
2683
match * cause_code {
@@ -2858,21 +2860,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2858
2860
}
2859
2861
}
2860
2862
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) ;
2864
2867
err. note ( with_forced_trimmed_paths ! ( format!(
2865
2868
"required for the cast from `{source}` to `{target}`" ,
2866
2869
) ) ) ;
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
- }
2876
2870
}
2877
2871
ObligationCauseCode :: RepeatElementCopy {
2878
2872
is_constable,
@@ -3175,8 +3169,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
3175
3169
// Don't print the tuple of capture types
3176
3170
' print: {
3177
3171
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) ;
3180
3173
let msg = format ! ( "required because it appears within the type `{ty_str}`" ) ;
3181
3174
match ty. kind ( ) {
3182
3175
ty:: Adt ( def, _) => match tcx. opt_item_ident ( def. did ( ) ) {
@@ -3274,9 +3267,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
3274
3267
let mut parent_trait_pred =
3275
3268
self . resolve_vars_if_possible ( data. derived . parent_trait_pred ) ;
3276
3269
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) ;
3280
3272
let trait_name = parent_trait_pred. print_modifiers_and_trait_path ( ) . to_string ( ) ;
3281
3273
let msg = format ! ( "required for `{self_ty_str}` to implement `{trait_name}`" ) ;
3282
3274
let mut is_auto_trait = false ;
@@ -3334,15 +3326,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
3334
3326
}
3335
3327
} ;
3336
3328
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
- }
3346
3329
let mut parent_predicate = parent_trait_pred;
3347
3330
let mut data = & data. derived ;
3348
3331
let mut count = 0 ;
@@ -3383,22 +3366,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
3383
3366
count,
3384
3367
pluralize!( count)
3385
3368
) ) ;
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
+ ) ;
3389
3373
err. note ( format ! (
3390
3374
"required for `{self_ty}` to implement `{}`" ,
3391
3375
parent_trait_pred. print_modifiers_and_trait_path( )
3392
3376
) ) ;
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
- }
3402
3377
}
3403
3378
// #74711: avoid a stack overflow
3404
3379
ensure_sufficient_stack ( || {
@@ -3507,8 +3482,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
3507
3482
}
3508
3483
ObligationCauseCode :: OpaqueReturnType ( expr_info) => {
3509
3484
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) ;
3512
3486
err. span_label (
3513
3487
expr_span,
3514
3488
with_forced_trimmed_paths ! ( format!(
@@ -3518,6 +3492,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
3518
3492
}
3519
3493
}
3520
3494
}
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
+ }
3521
3503
}
3522
3504
3523
3505
#[ instrument(
0 commit comments