@@ -6,11 +6,13 @@ use crate::infer::{ValuePairs, Subtype};
66use crate :: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
77use crate :: infer:: lexical_region_resolve:: RegionResolutionError ;
88use crate :: util:: common:: ErrorReported ;
9+ use crate :: traits:: ObligationCauseCode :: CompareImplMethodObligation ;
910
1011impl < ' a , ' tcx > NiceRegionError < ' a , ' tcx > {
1112 /// Print the error message for lifetime errors when the `impl` doesn't conform to the `trait`.
1213 pub ( super ) fn try_report_impl_not_conforming_to_trait ( & self ) -> Option < ErrorReported > {
1314 if let Some ( ref error) = self . error {
15+ debug ! ( "try_report_impl_not_conforming_to_trait {:?}" , error) ;
1416 if let RegionResolutionError :: SubSupConflict (
1517 _,
1618 var_origin,
@@ -27,10 +29,18 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2729 ) = ( & sub_trace. values , & sup_trace. values ) {
2830 if sup_expected_found == sub_expected_found {
2931 let sp = var_origin. span ( ) ;
32+ let impl_sp = if let CompareImplMethodObligation {
33+ trait_item_def_id, ..
34+ } = & sub_trace. cause . code {
35+ Some ( self . tcx ( ) . def_span ( * trait_item_def_id) )
36+ } else {
37+ None
38+ } ;
3039 self . emit_err (
3140 sp,
3241 sub_expected_found. expected ,
3342 sub_expected_found. found ,
43+ impl_sp,
3444 ) ;
3545 return Some ( ErrorReported ) ;
3646 }
@@ -43,14 +53,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4353 None
4454 }
4555
46- fn emit_err ( & self , sp : Span , expected : Ty < ' tcx > , found : Ty < ' tcx > ) {
56+ fn emit_err ( & self , sp : Span , expected : Ty < ' tcx > , found : Ty < ' tcx > , impl_sp : Option < Span > ) {
4757 let mut err = self . tcx ( ) . sess . struct_span_err (
4858 sp,
4959 "`impl` item signature doesn't match `trait` item signature" ,
5060 ) ;
51- err. note ( & format ! ( "expected: {:?}\n found: {:?}" , expected, found) ) ;
61+ err. note ( & format ! ( "expected ` {:?}` \n found ` {:?}` " , expected, found) ) ;
5262 err. span_label ( sp, & format ! ( "found {:?}" , found) ) ;
53- // FIXME: recover the `FnPtr`'s `HirId`/`Node` to point to it.
63+ if let Some ( span) = impl_sp {
64+ err. span_label ( span, & format ! ( "expected {:?}" , expected) ) ;
65+ }
5466 err. emit ( ) ;
5567 }
5668}
0 commit comments