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

librustc: Improve error message for incompatible trait method signatures... #13333

Merged
merged 1 commit into from
Apr 5, 2014
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
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ fn compare_impl_method(tcx: &ty::ctxt,
result::Err(ref terr) => {
tcx.sess.span_err(
impl_m_span,
format!("method `{}` has an incompatible type: {}",
format!("method `{}` has an incompatible type for trait: {}",
token::get_ident(trait_m.ident),
ty::type_err_to_str(tcx, terr)));
ty::note_and_explain_type_err(tcx, terr);
Expand Down
33 changes: 32 additions & 1 deletion src/test/compile-fail/wrong-mul-method-signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,52 @@
// (In this case the mul method should take &f64 and not f64)
// See: #11450

struct Vec1 {
x: f64
}

// Expecting ref in input signature
impl Mul<f64, Vec1> for Vec1 {
fn mul(&self, s: f64) -> Vec1 {
//~^ ERROR: method `mul` has an incompatible type for trait: expected &-ptr but found f64
Vec1 {
x: self.x * s
}
}
}

struct Vec2 {
x: f64,
y: f64
}

// Wrong type parameter ordering
impl Mul<Vec2, f64> for Vec2 {
fn mul(&self, s: f64) -> Vec2 {
//~^ ERROR: method `mul` has an incompatible type: expected &-ptr but found f64
//~^ ERROR: method `mul` has an incompatible type for trait: expected &-ptr but found f64
Vec2 {
x: self.x * s,
y: self.y * s
}
}
}

struct Vec3 {
x: f64,
y: f64,
z: f64
}

// Unexpected return type
impl Mul<f64, i32> for Vec3 {
fn mul(&self, s: &f64) -> f64 {
//~^ ERROR: method `mul` has an incompatible type for trait: expected i32 but found f64
*s
}
}

pub fn main() {
Vec1 { x: 1.0 } * 2.0;
Vec2 { x: 1.0, y: 2.0 } * 2.0;
Vec3 { x: 1.0, y: 2.0, z: 3.0 } * 2.0;
}