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