File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
librustc/middle/typeck/check Expand file tree Collapse file tree 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,
923923 result:: Err ( ref terr) => {
924924 tcx. sess . span_err (
925925 impl_m_span,
926- format ! ( "method `{}` has an incompatible type: {}" ,
926+ format ! ( "method `{}` has an incompatible type for trait : {}" ,
927927 token:: get_ident( trait_m. ident) ,
928928 ty:: type_err_to_str( tcx, terr) ) ) ;
929929 ty:: note_and_explain_type_err ( tcx, terr) ;
Original file line number Diff line number Diff line change 1313// (In this case the mul method should take &f64 and not f64)
1414// See: #11450
1515
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+
1630struct Vec2 {
1731 x : f64 ,
1832 y : f64
1933}
2034
35+ // Wrong type parameter ordering
2136impl Mul < Vec2 , f64 > for Vec2 {
2237 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
2439 Vec2 {
2540 x : self . x * s,
2641 y : self . y * s
2742 }
2843 }
2944}
3045
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+
3160pub fn main ( ) {
61+ Vec1 { x : 1.0 } * 2.0 ;
3262 Vec2 { x : 1.0 , y : 2.0 } * 2.0 ;
63+ Vec3 { x : 1.0 , y : 2.0 , z : 3.0 } * 2.0 ;
3364}
You can’t perform that action at this time.
0 commit comments