@@ -249,12 +249,12 @@ pub trait ErrorReporting<'tcx> {
249
249
terr : & TypeError < ' tcx > )
250
250
-> DiagnosticBuilder < ' tcx > ;
251
251
252
- fn values_str ( & self , values : & ValuePairs < ' tcx > ) -> Option < String > ;
252
+ fn values_str ( & self , values : & ValuePairs < ' tcx > ) -> Option < ( String , String ) > ;
253
253
254
254
fn expected_found_str < T : fmt:: Display + Resolvable < ' tcx > + TypeFoldable < ' tcx > > (
255
255
& self ,
256
256
exp_found : & ty:: error:: ExpectedFound < T > )
257
- -> Option < String > ;
257
+ -> Option < ( String , String ) > ;
258
258
259
259
fn report_concrete_failure ( & self ,
260
260
origin : SubregionOrigin < ' tcx > ,
@@ -535,7 +535,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
535
535
trace : TypeTrace < ' tcx > ,
536
536
terr : & TypeError < ' tcx > )
537
537
-> DiagnosticBuilder < ' tcx > {
538
- let expected_found_str = match self . values_str ( & trace. values ) {
538
+ let ( expected , found ) = match self . values_str ( & trace. values ) {
539
539
Some ( v) => v,
540
540
None => {
541
541
return self . tcx . sess . diagnostic ( ) . struct_dummy ( ) ; /* derived error */
@@ -548,18 +548,17 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
548
548
false
549
549
} ;
550
550
551
- let expected_found_str = if is_simple_error {
552
- expected_found_str
553
- } else {
554
- format ! ( "{} ({})" , expected_found_str, terr)
555
- } ;
556
-
557
551
let mut err = struct_span_err ! ( self . tcx. sess,
558
552
trace. origin. span( ) ,
559
553
E0308 ,
560
- "{}: {}" ,
561
- trace. origin,
562
- expected_found_str) ;
554
+ "{}" ,
555
+ trace. origin) ;
556
+
557
+ if !is_simple_error {
558
+ err = err. note_expected_found ( & "type" , & expected, & found) ;
559
+ }
560
+
561
+ err = err. span_label ( trace. origin . span ( ) , & terr) ;
563
562
564
563
self . check_and_note_conflicting_crates ( & mut err, terr, trace. origin . span ( ) ) ;
565
564
@@ -574,6 +573,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
574
573
} ,
575
574
_ => ( )
576
575
}
576
+
577
577
err
578
578
}
579
579
@@ -631,7 +631,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
631
631
632
632
/// Returns a string of the form "expected `{}`, found `{}`", or None if this is a derived
633
633
/// error.
634
- fn values_str ( & self , values : & ValuePairs < ' tcx > ) -> Option < String > {
634
+ fn values_str ( & self , values : & ValuePairs < ' tcx > ) -> Option < ( String , String ) > {
635
635
match * values {
636
636
infer:: Types ( ref exp_found) => self . expected_found_str ( exp_found) ,
637
637
infer:: TraitRefs ( ref exp_found) => self . expected_found_str ( exp_found) ,
@@ -642,7 +642,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
642
642
fn expected_found_str < T : fmt:: Display + Resolvable < ' tcx > + TypeFoldable < ' tcx > > (
643
643
& self ,
644
644
exp_found : & ty:: error:: ExpectedFound < T > )
645
- -> Option < String >
645
+ -> Option < ( String , String ) >
646
646
{
647
647
let expected = exp_found. expected . resolve ( self ) ;
648
648
if expected. references_error ( ) {
@@ -654,9 +654,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
654
654
return None ;
655
655
}
656
656
657
- Some ( format ! ( "expected `{}`, found `{}`" ,
658
- expected,
659
- found) )
657
+ Some ( ( format ! ( "{}" , expected) , format ! ( "{}" , found) ) )
660
658
}
661
659
662
660
fn report_generic_bound_failure ( & self ,
@@ -684,10 +682,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
684
682
E0309 ,
685
683
"{} may not live long enough" ,
686
684
labeled_user_string) ;
687
- err. fileline_help ( origin. span ( ) ,
688
- & format ! ( "consider adding an explicit lifetime bound `{}: {}`..." ,
689
- bound_kind,
690
- sub) ) ;
685
+ err. help ( & format ! ( "consider adding an explicit lifetime bound `{}: {}`..." ,
686
+ bound_kind,
687
+ sub) ) ;
691
688
err
692
689
}
693
690
@@ -698,10 +695,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
698
695
E0310 ,
699
696
"{} may not live long enough" ,
700
697
labeled_user_string) ;
701
- err. fileline_help ( origin. span ( ) ,
702
- & format ! ( "consider adding an explicit lifetime \
703
- bound `{}: 'static`...",
704
- bound_kind) ) ;
698
+ err. help ( & format ! ( "consider adding an explicit lifetime \
699
+ bound `{}: 'static`...",
700
+ bound_kind) ) ;
705
701
err
706
702
}
707
703
@@ -712,9 +708,8 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
712
708
E0311 ,
713
709
"{} may not live long enough" ,
714
710
labeled_user_string) ;
715
- err. fileline_help ( origin. span ( ) ,
716
- & format ! ( "consider adding an explicit lifetime bound for `{}`" ,
717
- bound_kind) ) ;
711
+ err. help ( & format ! ( "consider adding an explicit lifetime bound for `{}`" ,
712
+ bound_kind) ) ;
718
713
self . tcx . note_and_explain_region (
719
714
& mut err,
720
715
& format ! ( "{} must be valid for " , labeled_user_string) ,
@@ -1751,11 +1746,11 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
1751
1746
} ;
1752
1747
1753
1748
match self . values_str ( & trace. values ) {
1754
- Some ( values_str ) => {
1749
+ Some ( ( expected , found ) ) => {
1755
1750
err. span_note (
1756
1751
trace. origin . span ( ) ,
1757
- & format ! ( "...so that {} ({})" ,
1758
- desc, values_str ) ) ;
1752
+ & format ! ( "...so that {} (expected {}, found {})" ,
1753
+ desc, expected , found ) ) ;
1759
1754
}
1760
1755
None => {
1761
1756
// Really should avoid printing this error at
0 commit comments