@@ -6,11 +6,13 @@ use crate::infer::{ValuePairs, Subtype};
6
6
use crate :: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
7
7
use crate :: infer:: lexical_region_resolve:: RegionResolutionError ;
8
8
use crate :: util:: common:: ErrorReported ;
9
+ use crate :: traits:: ObligationCauseCode :: CompareImplMethodObligation ;
9
10
10
11
impl < ' a , ' tcx > NiceRegionError < ' a , ' tcx > {
11
12
/// Print the error message for lifetime errors when the `impl` doesn't conform to the `trait`.
12
13
pub ( super ) fn try_report_impl_not_conforming_to_trait ( & self ) -> Option < ErrorReported > {
13
14
if let Some ( ref error) = self . error {
15
+ debug ! ( "try_report_impl_not_conforming_to_trait {:?}" , error) ;
14
16
if let RegionResolutionError :: SubSupConflict (
15
17
_,
16
18
var_origin,
@@ -27,10 +29,18 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
27
29
) = ( & sub_trace. values , & sup_trace. values ) {
28
30
if sup_expected_found == sub_expected_found {
29
31
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
+ } ;
30
39
self . emit_err (
31
40
sp,
32
41
sub_expected_found. expected ,
33
42
sub_expected_found. found ,
43
+ impl_sp,
34
44
) ;
35
45
return Some ( ErrorReported ) ;
36
46
}
@@ -43,14 +53,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
43
53
None
44
54
}
45
55
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 > ) {
47
57
let mut err = self . tcx ( ) . sess . struct_span_err (
48
58
sp,
49
59
"`impl` item signature doesn't match `trait` item signature" ,
50
60
) ;
51
- err. note ( & format ! ( "expected: {:?}\n found: {:?}" , expected, found) ) ;
61
+ err. note ( & format ! ( "expected ` {:?}` \n found ` {:?}` " , expected, found) ) ;
52
62
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
+ }
54
66
err. emit ( ) ;
55
67
}
56
68
}
0 commit comments