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 E0049 to new error format #36383

Merged
merged 1 commit into from
Sep 16, 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
35 changes: 32 additions & 3 deletions src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
impl_m_span: Span,
impl_m_body_id: ast::NodeId,
trait_m: &ty::Method<'tcx>,
impl_trait_ref: &ty::TraitRef<'tcx>) {
impl_trait_ref: &ty::TraitRef<'tcx>,
trait_item_span: Option<Span>) {
debug!("compare_impl_method(impl_trait_ref={:?})",
impl_trait_ref);

Expand Down Expand Up @@ -97,14 +98,42 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
let num_impl_m_type_params = impl_m.generics.types.len();
let num_trait_m_type_params = trait_m.generics.types.len();
if num_impl_m_type_params != num_trait_m_type_params {
span_err!(tcx.sess, impl_m_span, E0049,
let impl_m_node_id = tcx.map.as_local_node_id(impl_m.def_id).unwrap();
let span = match tcx.map.expect_impl_item(impl_m_node_id).node {
ImplItemKind::Method(ref impl_m_sig, _) => {
if impl_m_sig.generics.is_parameterized() {
impl_m_sig.generics.span
} else {
impl_m_span
}
}
_ => bug!("{:?} is not a method", impl_m)
};

struct_span_err!(tcx.sess, span, E0049,
"method `{}` has {} type parameter{} \
but its trait declaration has {} type parameter{}",
trait_m.name,
num_impl_m_type_params,
if num_impl_m_type_params == 1 {""} else {"s"},
num_trait_m_type_params,
if num_trait_m_type_params == 1 {""} else {"s"});
if num_trait_m_type_params == 1 {""} else {"s"})
.span_label(trait_item_span.unwrap(),
&format!("expected {}",
&if num_trait_m_type_params != 1 {
format!("{} type parameters",
num_trait_m_type_params)
} else {
format!("{} type parameter",
num_trait_m_type_params)
}))
.span_label(span, &format!("found {}",
&if num_impl_m_type_params != 1 {
format!("{} type parameters", num_impl_m_type_params)
} else {
format!("1 type parameter")
}))
.emit();
return;
}

Expand Down
4 changes: 3 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,13 +1015,15 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
_ => span_bug!(impl_item.span, "non-method impl-item for method")
};

let trait_span = tcx.map.span_if_local(ty_trait_item.def_id());
if let &ty::MethodTraitItem(ref trait_method) = ty_trait_item {
compare_impl_method(ccx,
&impl_method,
impl_item.span,
body.id,
&trait_method,
&impl_trait_ref);
&impl_trait_ref,
trait_span);
} else {
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0324,
"item `{}` is an associated method, \
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/E0049.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
// except according to those terms.

trait Foo {
fn foo<T: Default>(x: T) -> Self;
fn foo<T: Default>(x: T) -> Self; //~ NOTE expected 1 type parameter
}

struct Bar;

impl Foo for Bar {
fn foo(x: bool) -> Self { Bar } //~ ERROR E0049
//~| NOTE found 0 type parameters
}

fn main() {
Expand Down