File tree 2 files changed +33
-2
lines changed
librustc/middle/typeck/check
2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -923,7 +923,7 @@ fn compare_impl_method(tcx: &ty::ctxt,
923
923
result:: Err ( ref terr) => {
924
924
tcx. sess . span_err (
925
925
impl_m_span,
926
- format ! ( "method `{}` has an incompatible type: {}" ,
926
+ format ! ( "method `{}` has an incompatible type for trait : {}" ,
927
927
token:: get_ident( trait_m. ident) ,
928
928
ty:: type_err_to_str( tcx, terr) ) ) ;
929
929
ty:: note_and_explain_type_err ( tcx, terr) ;
Original file line number Diff line number Diff line change 13
13
// (In this case the mul method should take &f64 and not f64)
14
14
// See: #11450
15
15
16
+ struct Vec1 {
17
+ x : f64
18
+ }
19
+
20
+ // Expecting ref in input signature
21
+ impl Mul < f64 , Vec1 > for Vec1 {
22
+ fn mul ( & self , s : f64 ) -> Vec1 {
23
+ //~^ ERROR: method `mul` has an incompatible type for trait: expected &-ptr but found f64
24
+ Vec1 {
25
+ x : self . x * s
26
+ }
27
+ }
28
+ }
29
+
16
30
struct Vec2 {
17
31
x : f64 ,
18
32
y : f64
19
33
}
20
34
35
+ // Wrong type parameter ordering
21
36
impl Mul < Vec2 , f64 > for Vec2 {
22
37
fn mul ( & self , s : f64 ) -> Vec2 {
23
- //~^ ERROR: method `mul` has an incompatible type: expected &-ptr but found f64
38
+ //~^ ERROR: method `mul` has an incompatible type for trait : expected &-ptr but found f64
24
39
Vec2 {
25
40
x : self . x * s,
26
41
y : self . y * s
27
42
}
28
43
}
29
44
}
30
45
46
+ struct Vec3 {
47
+ x : f64 ,
48
+ y : f64 ,
49
+ z : f64
50
+ }
51
+
52
+ // Unexpected return type
53
+ impl Mul < f64 , i32 > for Vec3 {
54
+ fn mul ( & self , s : & f64 ) -> f64 {
55
+ //~^ ERROR: method `mul` has an incompatible type for trait: expected i32 but found f64
56
+ * s
57
+ }
58
+ }
59
+
31
60
pub fn main ( ) {
61
+ Vec1 { x : 1.0 } * 2.0 ;
32
62
Vec2 { x : 1.0 , y : 2.0 } * 2.0 ;
63
+ Vec3 { x : 1.0 , y : 2.0 , z : 3.0 } * 2.0 ;
33
64
}
You can’t perform that action at this time.
0 commit comments