Skip to content

Commit

Permalink
Rollup merge of rust-lang#36135 - 0xmohit:pr/error-code-E0520, r=jona…
Browse files Browse the repository at this point in the history
…thandturner

Update E0520 to new error format

Fixes rust-lang#36112.
Part of rust-lang#35233.

r? @jonathandturner
  • Loading branch information
Jonathan Turner authored Aug 31, 2016
2 parents 422305a + 77cd09a commit f3ce9fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,14 +903,18 @@ fn report_forbidden_specialization<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
{
let mut err = struct_span_err!(
tcx.sess, impl_item.span, E0520,
"item `{}` is provided by an `impl` that specializes \
another, but the item in the parent `impl` is not \
marked `default` and so it cannot be specialized.",
"`{}` specializes an item from a parent `impl`, but \
neither that item nor the `impl` are marked `default`",
impl_item.name);
err.span_label(impl_item.span, &format!("cannot specialize default item `{}`",
impl_item.name));

match tcx.span_of_impl(parent_impl) {
Ok(span) => {
err.span_note(span, "parent implementation is here:");
err.span_label(span, &"parent `impl` is here");
err.note(&format!("to specialize, either the parent `impl` or `{}` \
in the parent `impl` must be marked `default`",
impl_item.name));
}
Err(cname) => {
err.note(&format!("parent implementation is in crate `{}`", cname));
Expand Down
6 changes: 5 additions & 1 deletion src/test/compile-fail/E0520.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ impl<T> SpaceLlama for T {
}

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

impl SpaceLlama for i32 {
default fn fly(&self) {} //~ ERROR E0520
default fn fly(&self) {}
//~^ ERROR E0520
//~| NOTE cannot specialize default item `fly`
//~| NOTE either the parent `impl` or `fly` in the parent `impl` must be marked `default`
}

fn main() {
Expand Down

0 comments on commit f3ce9fd

Please sign in to comment.