]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/modulo_one.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / modulo_one.rs
1 #![warn(clippy::modulo_one)]
2 #![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::identity_op)]
3
4 static STATIC_ONE: usize = 2 - 1;
5 static STATIC_NEG_ONE: i64 = 1 - 2;
6
7 fn main() {
8 10 % 1;
9 //~^ ERROR: any number modulo 1 will be 0
10 //~| NOTE: `-D clippy::modulo-one` implied by `-D warnings`
11 10 % -1;
12 //~^ ERROR: any number modulo -1 will panic/overflow or result in 0
13 10 % 2;
14 // also caught by rustc
15 i32::MIN % (-1);
16 //~^ ERROR: this operation will panic at runtime
17 //~| NOTE: `#[deny(unconditional_panic)]` on by default
18 //~| ERROR: any number modulo -1 will panic/overflow or result in 0
19
20 const ONE: u32 = 1 * 1;
21 const NEG_ONE: i64 = 1 - 2;
22 const INT_MIN: i64 = i64::MIN;
23
24 2 % ONE;
25 //~^ ERROR: any number modulo 1 will be 0
26 // NOT caught by lint
27 5 % STATIC_ONE;
28 2 % NEG_ONE;
29 //~^ ERROR: any number modulo -1 will panic/overflow or result in 0
30 // NOT caught by lint
31 5 % STATIC_NEG_ONE;
32 // also caught by rustc
33 INT_MIN % NEG_ONE;
34 //~^ ERROR: this operation will panic at runtime
35 //~| ERROR: any number modulo -1 will panic/overflow or result in 0
36 // ONLY caught by rustc
37 INT_MIN % STATIC_NEG_ONE;
38 //~^ ERROR: this operation will panic at runtime
39 }