mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
librustc: Improve error message for incompatible trait method signatures.
This commit is contained in:
parent
4cf8d8ce69
commit
28938d08a0
@ -923,7 +923,7 @@ fn compare_impl_method(tcx: &ty::ctxt,
|
|||||||
result::Err(ref terr) => {
|
result::Err(ref terr) => {
|
||||||
tcx.sess.span_err(
|
tcx.sess.span_err(
|
||||||
impl_m_span,
|
impl_m_span,
|
||||||
format!("method `{}` has an incompatible type: {}",
|
format!("method `{}` has an incompatible type for trait: {}",
|
||||||
token::get_ident(trait_m.ident),
|
token::get_ident(trait_m.ident),
|
||||||
ty::type_err_to_str(tcx, terr)));
|
ty::type_err_to_str(tcx, terr)));
|
||||||
ty::note_and_explain_type_err(tcx, terr);
|
ty::note_and_explain_type_err(tcx, terr);
|
||||||
|
@ -13,14 +13,29 @@
|
|||||||
// (In this case the mul method should take &f64 and not f64)
|
// (In this case the mul method should take &f64 and not f64)
|
||||||
// See: #11450
|
// 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 {
|
struct Vec2 {
|
||||||
x: f64,
|
x: f64,
|
||||||
y: f64
|
y: f64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wrong type parameter ordering
|
||||||
impl Mul<Vec2, f64> for Vec2 {
|
impl Mul<Vec2, f64> for Vec2 {
|
||||||
fn mul(&self, s: f64) -> 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 {
|
Vec2 {
|
||||||
x: self.x * s,
|
x: self.x * s,
|
||||||
y: self.y * s
|
y: self.y * s
|
||||||
@ -28,6 +43,22 @@ impl Mul<Vec2, f64> for Vec2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() {
|
struct Vec3 {
|
||||||
Vec2 { x: 1.0, y: 2.0 } * 2.0;
|
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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user