Skip to content

Commit 77cd09a

Browse files
committed
Update E0520 to new error format
Fixes #36112. Part of #35233. r? @jonathandturner
1 parent 71ee82a commit 77cd09a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/librustc_typeck/check/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -903,14 +903,18 @@ fn report_forbidden_specialization<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
903903
{
904904
let mut err = struct_span_err!(
905905
tcx.sess, impl_item.span, E0520,
906-
"item `{}` is provided by an `impl` that specializes \
907-
another, but the item in the parent `impl` is not \
908-
marked `default` and so it cannot be specialized.",
906+
"`{}` specializes an item from a parent `impl`, but \
907+
neither that item nor the `impl` are marked `default`",
909908
impl_item.name);
909+
err.span_label(impl_item.span, &format!("cannot specialize default item `{}`",
910+
impl_item.name));
910911

911912
match tcx.span_of_impl(parent_impl) {
912913
Ok(span) => {
913-
err.span_note(span, "parent implementation is here:");
914+
err.span_label(span, &"parent `impl` is here");
915+
err.note(&format!("to specialize, either the parent `impl` or `{}` \
916+
in the parent `impl` must be marked `default`",
917+
impl_item.name));
914918
}
915919
Err(cname) => {
916920
err.note(&format!("parent implementation is in crate `{}`", cname));

src/test/compile-fail/E0520.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ impl<T> SpaceLlama for T {
1919
}
2020

2121
impl<T: Clone> SpaceLlama for T {
22+
//~^ NOTE parent `impl` is here
2223
fn fly(&self) {}
2324
}
2425

2526
impl SpaceLlama for i32 {
26-
default fn fly(&self) {} //~ ERROR E0520
27+
default fn fly(&self) {}
28+
//~^ ERROR E0520
29+
//~| NOTE cannot specialize default item `fly`
30+
//~| NOTE either the parent `impl` or `fly` in the parent `impl` must be marked `default`
2731
}
2832

2933
fn main() {

0 commit comments

Comments
 (0)