Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error message for E0323, E0324 and E0325 #35372

Merged
merged 1 commit into from
Aug 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
// Check existing impl methods to see if they are both present in trait
// and compatible with trait signature
for impl_item in impl_items {
let ty_impl_item = ccx.tcx.impl_or_trait_item(ccx.tcx.map.local_def_id(impl_item.id));
let ty_impl_item = tcx.impl_or_trait_item(tcx.map.local_def_id(impl_item.id));
let ty_trait_item = trait_items.iter()
.find(|ac| ac.name() == ty_impl_item.name());

Expand All @@ -1014,11 +1014,18 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
trait_const,
&impl_trait_ref);
} else {
span_err!(tcx.sess, impl_item.span, E0323,
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0323,
"item `{}` is an associated const, \
which doesn't match its trait `{:?}`",
impl_const.name,
impl_trait_ref)
impl_trait_ref);
err.span_label(impl_item.span, &format!("does not match trait"));
// We can only get the spans from local trait definition
// Same for E0324 and E0325
if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) {
err.span_label(trait_span, &format!("original trait requirement"));
}
err.emit()
}
}
hir::ImplItemKind::Method(ref sig, ref body) => {
Expand All @@ -1037,11 +1044,16 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
&trait_method,
&impl_trait_ref);
} else {
span_err!(tcx.sess, impl_item.span, E0324,
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0324,
"item `{}` is an associated method, \
which doesn't match its trait `{:?}`",
impl_method.name,
impl_trait_ref)
impl_trait_ref);
err.span_label(impl_item.span, &format!("does not match trait"));
if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) {
err.span_label(trait_span, &format!("original trait requirement"));
}
err.emit()
}
}
hir::ImplItemKind::Type(_) => {
Expand All @@ -1055,11 +1067,16 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
overridden_associated_type = Some(impl_item);
}
} else {
span_err!(tcx.sess, impl_item.span, E0325,
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0325,
"item `{}` is an associated type, \
which doesn't match its trait `{:?}`",
impl_type.name,
impl_trait_ref)
impl_trait_ref);
err.span_label(impl_item.span, &format!("does not match trait"));
if let Some(trait_span) = tcx.map.span_if_local(ty_trait_item.def_id()) {
err.span_label(trait_span, &format!("original trait requirement"));
}
err.emit()
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/test/compile-fail/impl-wrong-item-for-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

trait Foo {
fn bar(&self);
const MY_CONST: u32;
//~^ NOTE original trait requirement
//~| NOTE original trait requirement
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to put that note twice because there are 2 different tests that display that note, is that normal or a bug?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's normal. Since there are actually three tests in this file, and two of them refer to that definition, you'll need one for each.

const MY_CONST: u32; //~ NOTE original trait requirement
}

pub struct FooConstForMethod;
Expand All @@ -21,6 +23,7 @@ impl Foo for FooConstForMethod {
//~^ ERROR E0046
const bar: u64 = 1;
//~^ ERROR E0323
//~| NOTE does not match trait
const MY_CONST: u32 = 1;
}

Expand All @@ -31,6 +34,7 @@ impl Foo for FooMethodForConst {
fn bar(&self) {}
fn MY_CONST() {}
//~^ ERROR E0324
//~| NOTE does not match trait
}

pub struct FooTypeForMethod;
Expand All @@ -39,6 +43,7 @@ impl Foo for FooTypeForMethod {
//~^ ERROR E0046
type bar = u64;
//~^ ERROR E0325
//~| NOTE does not match trait
const MY_CONST: u32 = 1;
}

Expand Down