1 // This test is to make sure we don't just ICE if the trait
2 // method for an operator is not implemented properly.
3 // (In this case the mul method should take &f64 and not f64)
4 // See: #11450
5
6 use std::ops::Mul;
7
8 struct Vec1 {
9 x: f64
10 }
11
12 // Expecting value in input signature
13 impl Mul<f64> for Vec1 {
14 type Output = Vec1;
15
mul(self, s: &f64) -> Vec116 fn mul(self, s: &f64) -> Vec1 {
17 //~^ ERROR method `mul` has an incompatible type for trait
18 Vec1 {
19 x: self.x * *s
20 }
21 }
22 }
23
24 struct Vec2 {
25 x: f64,
26 y: f64
27 }
28
29 // Wrong type parameter ordering
30 impl Mul<Vec2> for Vec2 {
31 type Output = f64;
32
mul(self, s: f64) -> Vec233 fn mul(self, s: f64) -> Vec2 {
34 //~^ ERROR method `mul` has an incompatible type for trait
35 Vec2 {
36 x: self.x * s,
37 y: self.y * s
38 }
39 }
40 }
41
42 struct Vec3 {
43 x: f64,
44 y: f64,
45 z: f64
46 }
47
48 // Unexpected return type
49 impl Mul<f64> for Vec3 {
50 type Output = i32;
51
mul(self, s: f64) -> f6452 fn mul(self, s: f64) -> f64 {
53 //~^ ERROR method `mul` has an incompatible type for trait
54 s
55 }
56 }
57
main()58 pub fn main() {
59 // Check that the usage goes from the trait declaration:
60
61 let x: Vec1 = Vec1 { x: 1.0 } * 2.0; // this is OK
62
63 let x: Vec2 = Vec2 { x: 1.0, y: 2.0 } * 2.0; // trait had reversed order
64 //~^ ERROR mismatched types
65 //~| ERROR mismatched types
66
67 let x: i32 = Vec3 { x: 1.0, y: 2.0, z: 3.0 } * 2.0;
68 }
69