55
66use core:: ops:: ControlFlow ;
77use std:: borrow:: Cow ;
8+ use std:: path:: PathBuf ;
89
910use hir:: Expr ;
1011use rustc_ast:: ast:: Mutability ;
@@ -362,14 +363,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
362363
363364 fn suggest_missing_writer ( & self , rcvr_ty : Ty < ' tcx > , rcvr_expr : & hir:: Expr < ' tcx > ) -> Diag < ' _ > {
364365 let mut file = None ;
365- let ty_str = self . tcx . short_ty_string ( rcvr_ty, & mut file) ;
366366 let mut err = struct_span_code_err ! (
367367 self . dcx( ) ,
368368 rcvr_expr. span,
369369 E0599 ,
370370 "cannot write into `{}`" ,
371- ty_str
371+ self . tcx . short_string ( rcvr_ty , & mut file ) ,
372372 ) ;
373+ * err. long_ty_path ( ) = file;
373374 err. span_note (
374375 rcvr_expr. span ,
375376 "must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method" ,
@@ -380,11 +381,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
380381 "a writer is needed before this format string" ,
381382 ) ;
382383 } ;
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-
388384 err
389385 }
390386
@@ -595,7 +591,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
595591 ( predicates. to_string ( ) , with_forced_trimmed_paths ! ( predicates. to_string( ) ) )
596592 } else {
597593 (
598- tcx. short_ty_string ( rcvr_ty, & mut ty_file) ,
594+ tcx. short_string ( rcvr_ty, & mut ty_file) ,
599595 with_forced_trimmed_paths ! ( rcvr_ty. to_string( ) ) ,
600596 )
601597 } ;
@@ -624,6 +620,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
624620 span,
625621 item_name,
626622 & short_ty_str,
623+ & mut ty_file,
627624 ) {
628625 return guar;
629626 }
@@ -635,6 +632,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
635632 item_kind,
636633 item_name,
637634 & short_ty_str,
635+ & mut ty_file,
638636 ) {
639637 return guar;
640638 }
@@ -728,10 +726,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
728726 ty_str = short_ty_str;
729727 }
730728
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- }
735729 if rcvr_ty. references_error ( ) {
736730 err. downgrade_to_delayed_bug ( ) ;
737731 }
@@ -1314,7 +1308,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13141308 bound_list. into_iter ( ) . map ( |( _, path) | path) . collect :: < Vec < _ > > ( ) . join ( "\n " ) ;
13151309 let actual_prefix = rcvr_ty. prefix_string ( self . tcx ) ;
13161310 info ! ( "unimplemented_traits.len() == {}" , unimplemented_traits. len( ) ) ;
1317- let mut long_ty_file = None ;
13181311 let ( primary_message, label, notes) = if unimplemented_traits. len ( ) == 1
13191312 && unimplemented_traits_only
13201313 {
@@ -1329,7 +1322,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13291322 }
13301323 let OnUnimplementedNote { message, label, notes, .. } = self
13311324 . err_ctxt ( )
1332- . on_unimplemented_note ( trait_ref, & obligation, & mut long_ty_file ) ;
1325+ . on_unimplemented_note ( trait_ref, & obligation, & mut ty_file ) ;
13331326 ( message, label, notes)
13341327 } )
13351328 . unwrap ( )
@@ -1343,15 +1336,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13431336 )
13441337 } ) ;
13451338 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- }
13551339 if let Some ( label) = label {
13561340 custom_span_label = true ;
13571341 err. span_label ( span, label) ;
@@ -2403,6 +2387,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24032387 span : Span ,
24042388 item_name : Ident ,
24052389 ty_str : & str ,
2390+ long_ty_path : & mut Option < PathBuf > ,
24062391 ) -> Result < ( ) , ErrorGuaranteed > {
24072392 if let SelfSource :: MethodCall ( expr) = source {
24082393 for ( _, parent) in tcx. hir ( ) . parent_iter ( expr. hir_id ) . take ( 5 ) {
@@ -2460,7 +2445,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24602445 ) ;
24612446 if pick. is_ok ( ) {
24622447 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 {
24642449 span,
24652450 ty_str : ty_str. to_string ( ) ,
24662451 method_name : item_name. as_str ( ) . to_string ( ) ,
@@ -2469,7 +2454,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24692454 left : range_span. shrink_to_lo ( ) ,
24702455 right : range_span. shrink_to_hi ( ) ,
24712456 } ) ,
2472- } ) ) ;
2457+ } ) ;
2458+ * err. long_ty_path ( ) = long_ty_path. take ( ) ;
2459+ return Err ( err. emit ( ) ) ;
24732460 }
24742461 }
24752462 }
@@ -2486,6 +2473,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24862473 item_kind : & str ,
24872474 item_name : Ident ,
24882475 ty_str : & str ,
2476+ long_ty_path : & mut Option < PathBuf > ,
24892477 ) -> Result < ( ) , ErrorGuaranteed > {
24902478 let found_candidate = all_traits ( self . tcx )
24912479 . into_iter ( )
@@ -2526,6 +2514,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25262514 item_name,
25272515 ty_str
25282516 ) ;
2517+ * err. long_ty_path ( ) = long_ty_path. take ( ) ;
25292518 let concrete_type = if actual. is_integral ( ) { "i32" } else { "f32" } ;
25302519 match expr. kind {
25312520 ExprKind :: Lit ( lit) => {
0 commit comments