summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/erasing_op.rs
blob: 00c74f23fed04a1a2a9ff62f2dbeb438d26ac3ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
struct Length(u8);
struct Meter;

impl core::ops::Mul<Meter> for u8 {
    type Output = Length;
    fn mul(self, _: Meter) -> Length {
        Length(self)
    }
}

#[derive(Clone, Default, PartialEq, Eq, Hash)]
struct Vec1 {
    x: i32,
}

impl core::ops::Mul<Vec1> for i32 {
    type Output = Vec1;
    fn mul(self, mut right: Vec1) -> Vec1 {
        right.x *= self;
        right
    }
}

impl core::ops::Mul<i32> for Vec1 {
    type Output = Vec1;
    fn mul(mut self, right: i32) -> Vec1 {
        self.x *= right;
        self
    }
}

#[allow(clippy::no_effect)]
#[warn(clippy::erasing_op)]
fn test(x: u8) {
    x * 0;
    //~^ ERROR: this operation will always return zero. This is likely not the intended ou
    //~| NOTE: `-D clippy::erasing-op` implied by `-D warnings`
    0 & x;
    //~^ ERROR: this operation will always return zero. This is likely not the intended ou
    0 / x;
    //~^ ERROR: this operation will always return zero. This is likely not the intended ou
    0 * Meter; // no error: Output type is different from the non-zero argument
    0 * Vec1 { x: 5 };
    //~^ ERROR: this operation will always return zero. This is likely not the intended ou
    Vec1 { x: 5 } * 0;
    //~^ ERROR: this operation will always return zero. This is likely not the intended ou
}

fn main() {
    test(0)
}