about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/integer_division_remainder_used.rs
blob: 4d3a7c5eaa1567ef0de003fda0460b0e5f4275ac (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
#![warn(clippy::integer_division_remainder_used)]
#![allow(unused_variables)]
#![allow(clippy::op_ref)]

struct CustomOps(pub i32);
impl std::ops::Div for CustomOps {
    type Output = Self;

    fn div(self, rhs: Self) -> Self::Output {
        Self(self.0 / rhs.0)
        //~^ integer_division_remainder_used
    }
}
impl std::ops::Rem for CustomOps {
    type Output = Self;

    fn rem(self, rhs: Self) -> Self::Output {
        Self(self.0 % rhs.0)
        //~^ integer_division_remainder_used
    }
}

fn main() {
    // should trigger
    let a = 10;
    let b = 5;
    let c = a / b;
    //~^ integer_division_remainder_used
    let d = a % b;
    //~^ integer_division_remainder_used
    let e = &a / b;
    //~^ integer_division_remainder_used
    let f = a % &b;
    //~^ integer_division_remainder_used
    let g = &a / &b;
    //~^ integer_division_remainder_used
    let h = &10 % b;
    //~^ integer_division_remainder_used
    let i = a / &4;
    //~^ integer_division_remainder_used

    // should not trigger on custom Div and Rem
    let w = CustomOps(3);
    let x = CustomOps(4);
    let y = w / x;

    let w = CustomOps(3);
    let x = CustomOps(4);
    let z = w % x;
}