5
5
6
6
use core:: ops:: ControlFlow ;
7
7
use std:: borrow:: Cow ;
8
+ use std:: path:: PathBuf ;
8
9
9
10
use hir:: Expr ;
10
11
use rustc_ast:: ast:: Mutability ;
@@ -362,14 +363,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
362
363
363
364
fn suggest_missing_writer ( & self , rcvr_ty : Ty < ' tcx > , rcvr_expr : & hir:: Expr < ' tcx > ) -> Diag < ' _ > {
364
365
let mut file = None ;
365
- let ty_str = self . tcx . short_ty_string ( rcvr_ty, & mut file) ;
366
366
let mut err = struct_span_code_err ! (
367
367
self . dcx( ) ,
368
368
rcvr_expr. span,
369
369
E0599 ,
370
370
"cannot write into `{}`" ,
371
- ty_str
371
+ self . tcx . short_string ( rcvr_ty , & mut file ) ,
372
372
) ;
373
+ * err. long_ty_path ( ) = file;
373
374
err. span_note (
374
375
rcvr_expr. span ,
375
376
"must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method" ,
@@ -380,11 +381,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
380
381
"a writer is needed before this format string" ,
381
382
) ;
382
383
} ;
383
- if let Some ( file) = file {
384
- err. note ( format ! ( "the full type name has been written to '{}'" , file. display( ) ) ) ;
385
- err. note ( "consider using `--verbose` to print the full type name to the console" ) ;
386
- }
387
-
388
384
err
389
385
}
390
386
@@ -595,7 +591,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
595
591
( predicates. to_string ( ) , with_forced_trimmed_paths ! ( predicates. to_string( ) ) )
596
592
} else {
597
593
(
598
- tcx. short_ty_string ( rcvr_ty, & mut ty_file) ,
594
+ tcx. short_string ( rcvr_ty, & mut ty_file) ,
599
595
with_forced_trimmed_paths ! ( rcvr_ty. to_string( ) ) ,
600
596
)
601
597
} ;
@@ -624,6 +620,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
624
620
span,
625
621
item_name,
626
622
& short_ty_str,
623
+ & mut ty_file,
627
624
) {
628
625
return guar;
629
626
}
@@ -635,6 +632,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
635
632
item_kind,
636
633
item_name,
637
634
& short_ty_str,
635
+ & mut ty_file,
638
636
) {
639
637
return guar;
640
638
}
@@ -728,10 +726,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
728
726
ty_str = short_ty_str;
729
727
}
730
728
731
- if let Some ( file) = ty_file {
732
- err. note ( format ! ( "the full type name has been written to '{}'" , file. display( ) , ) ) ;
733
- err. note ( "consider using `--verbose` to print the full type name to the console" ) ;
734
- }
735
729
if rcvr_ty. references_error ( ) {
736
730
err. downgrade_to_delayed_bug ( ) ;
737
731
}
@@ -1314,7 +1308,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1314
1308
bound_list. into_iter ( ) . map ( |( _, path) | path) . collect :: < Vec < _ > > ( ) . join ( "\n " ) ;
1315
1309
let actual_prefix = rcvr_ty. prefix_string ( self . tcx ) ;
1316
1310
info ! ( "unimplemented_traits.len() == {}" , unimplemented_traits. len( ) ) ;
1317
- let mut long_ty_file = None ;
1318
1311
let ( primary_message, label, notes) = if unimplemented_traits. len ( ) == 1
1319
1312
&& unimplemented_traits_only
1320
1313
{
@@ -1329,7 +1322,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1329
1322
}
1330
1323
let OnUnimplementedNote { message, label, notes, .. } = self
1331
1324
. err_ctxt ( )
1332
- . on_unimplemented_note ( trait_ref, & obligation, & mut long_ty_file ) ;
1325
+ . on_unimplemented_note ( trait_ref, & obligation, & mut ty_file ) ;
1333
1326
( message, label, notes)
1334
1327
} )
1335
1328
. unwrap ( )
@@ -1343,15 +1336,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1343
1336
)
1344
1337
} ) ;
1345
1338
err. primary_message ( primary_message) ;
1346
- if let Some ( file) = long_ty_file {
1347
- err. note ( format ! (
1348
- "the full name for the type has been written to '{}'" ,
1349
- file. display( ) ,
1350
- ) ) ;
1351
- err. note (
1352
- "consider using `--verbose` to print the full type name to the console" ,
1353
- ) ;
1354
- }
1355
1339
if let Some ( label) = label {
1356
1340
custom_span_label = true ;
1357
1341
err. span_label ( span, label) ;
@@ -2403,6 +2387,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2403
2387
span : Span ,
2404
2388
item_name : Ident ,
2405
2389
ty_str : & str ,
2390
+ long_ty_path : & mut Option < PathBuf > ,
2406
2391
) -> Result < ( ) , ErrorGuaranteed > {
2407
2392
if let SelfSource :: MethodCall ( expr) = source {
2408
2393
for ( _, parent) in tcx. hir ( ) . parent_iter ( expr. hir_id ) . take ( 5 ) {
@@ -2460,7 +2445,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2460
2445
) ;
2461
2446
if pick. is_ok ( ) {
2462
2447
let range_span = parent_expr. span . with_hi ( expr. span . hi ( ) ) ;
2463
- return Err ( self . dcx ( ) . emit_err ( errors:: MissingParenthesesInRange {
2448
+ let mut err = self . dcx ( ) . create_err ( errors:: MissingParenthesesInRange {
2464
2449
span,
2465
2450
ty_str : ty_str. to_string ( ) ,
2466
2451
method_name : item_name. as_str ( ) . to_string ( ) ,
@@ -2469,7 +2454,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2469
2454
left : range_span. shrink_to_lo ( ) ,
2470
2455
right : range_span. shrink_to_hi ( ) ,
2471
2456
} ) ,
2472
- } ) ) ;
2457
+ } ) ;
2458
+ * err. long_ty_path ( ) = long_ty_path. take ( ) ;
2459
+ return Err ( err. emit ( ) ) ;
2473
2460
}
2474
2461
}
2475
2462
}
@@ -2486,6 +2473,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2486
2473
item_kind : & str ,
2487
2474
item_name : Ident ,
2488
2475
ty_str : & str ,
2476
+ long_ty_path : & mut Option < PathBuf > ,
2489
2477
) -> Result < ( ) , ErrorGuaranteed > {
2490
2478
let found_candidate = all_traits ( self . tcx )
2491
2479
. into_iter ( )
@@ -2526,6 +2514,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2526
2514
item_name,
2527
2515
ty_str
2528
2516
) ;
2517
+ * err. long_ty_path ( ) = long_ty_path. take ( ) ;
2529
2518
let concrete_type = if actual. is_integral ( ) { "i32" } else { "f32" } ;
2530
2519
match expr. kind {
2531
2520
ExprKind :: Lit ( lit) => {
0 commit comments