@@ -995,7 +995,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
995
995
// Check existing impl methods to see if they are both present in trait
996
996
// and compatible with trait signature
997
997
for impl_item in impl_items {
998
- let ty_impl_item = ccx . tcx . impl_or_trait_item ( ccx . tcx . map . local_def_id ( impl_item. id ) ) ;
998
+ let ty_impl_item = tcx. impl_or_trait_item ( tcx. map . local_def_id ( impl_item. id ) ) ;
999
999
let ty_trait_item = trait_items. iter ( )
1000
1000
. find ( |ac| ac. name ( ) == ty_impl_item. name ( ) ) ;
1001
1001
@@ -1016,11 +1016,18 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
1016
1016
trait_const,
1017
1017
& impl_trait_ref) ;
1018
1018
} else {
1019
- span_err ! ( tcx. sess, impl_item. span, E0323 ,
1019
+ let mut err = struct_span_err ! ( tcx. sess, impl_item. span, E0323 ,
1020
1020
"item `{}` is an associated const, \
1021
1021
which doesn't match its trait `{:?}`",
1022
1022
impl_const. name,
1023
- impl_trait_ref)
1023
+ impl_trait_ref) ;
1024
+ err. span_label ( impl_item. span , & format ! ( "does not match trait" ) ) ;
1025
+ // We can only get the spans from local trait definition
1026
+ // Same for E0324 and E0325
1027
+ if let Some ( trait_span) = tcx. map . span_if_local ( ty_trait_item. def_id ( ) ) {
1028
+ err. span_label ( trait_span, & format ! ( "original trait requirement" ) ) ;
1029
+ }
1030
+ err. emit ( )
1024
1031
}
1025
1032
}
1026
1033
hir:: ImplItemKind :: Method ( ref sig, ref body) => {
@@ -1039,11 +1046,16 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
1039
1046
& trait_method,
1040
1047
& impl_trait_ref) ;
1041
1048
} else {
1042
- span_err ! ( tcx. sess, impl_item. span, E0324 ,
1049
+ let mut err = struct_span_err ! ( tcx. sess, impl_item. span, E0324 ,
1043
1050
"item `{}` is an associated method, \
1044
1051
which doesn't match its trait `{:?}`",
1045
1052
impl_method. name,
1046
- impl_trait_ref)
1053
+ impl_trait_ref) ;
1054
+ err. span_label ( impl_item. span , & format ! ( "does not match trait" ) ) ;
1055
+ if let Some ( trait_span) = tcx. map . span_if_local ( ty_trait_item. def_id ( ) ) {
1056
+ err. span_label ( trait_span, & format ! ( "original trait requirement" ) ) ;
1057
+ }
1058
+ err. emit ( )
1047
1059
}
1048
1060
}
1049
1061
hir:: ImplItemKind :: Type ( _) => {
@@ -1057,11 +1069,16 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
1057
1069
overridden_associated_type = Some ( impl_item) ;
1058
1070
}
1059
1071
} else {
1060
- span_err ! ( tcx. sess, impl_item. span, E0325 ,
1072
+ let mut err = struct_span_err ! ( tcx. sess, impl_item. span, E0325 ,
1061
1073
"item `{}` is an associated type, \
1062
1074
which doesn't match its trait `{:?}`",
1063
1075
impl_type. name,
1064
- impl_trait_ref)
1076
+ impl_trait_ref) ;
1077
+ err. span_label ( impl_item. span , & format ! ( "does not match trait" ) ) ;
1078
+ if let Some ( trait_span) = tcx. map . span_if_local ( ty_trait_item. def_id ( ) ) {
1079
+ err. span_label ( trait_span, & format ! ( "original trait requirement" ) ) ;
1080
+ }
1081
+ err. emit ( )
1065
1082
}
1066
1083
}
1067
1084
}
0 commit comments