]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/manual_rem_euclid.fixed
Merge commit '0cb0f7636851f9fcc57085cf80197a2ef6db098f' into clippyup
[rust.git] / src / tools / clippy / tests / ui / manual_rem_euclid.fixed
1 // run-rustfix
2 // aux-build:macro_rules.rs
3
4 #![warn(clippy::manual_rem_euclid)]
5
6 #[macro_use]
7 extern crate macro_rules;
8
9 macro_rules! internal_rem_euclid {
10     () => {
11         let value: i32 = 5;
12         let _: i32 = value.rem_euclid(4);
13     };
14 }
15
16 fn main() {
17     let value: i32 = 5;
18
19     let _: i32 = value.rem_euclid(4);
20     let _: i32 = value.rem_euclid(4);
21     let _: i32 = value.rem_euclid(4);
22     let _: i32 = value.rem_euclid(4);
23     let _: i32 = 1 + value.rem_euclid(4);
24
25     let _: i32 = (3 + value % 4) % 4;
26     let _: i32 = (-4 + value % -4) % -4;
27     let _: i32 = ((5 % 4) + 4) % 4;
28
29     // Make sure the lint does not trigger if it would cause an error, like with an ambiguous
30     // integer type
31     let not_annotated = 24;
32     let _ = ((not_annotated % 4) + 4) % 4;
33     let inferred: _ = 24;
34     let _ = ((inferred % 4) + 4) % 4;
35
36     // For lint to apply the constant must always be on the RHS of the previous value for %
37     let _: i32 = 4 % ((value % 4) + 4);
38     let _: i32 = ((4 % value) + 4) % 4;
39
40     // Lint in internal macros
41     internal_rem_euclid!();
42
43     // Do not lint in external macros
44     manual_rem_euclid!();
45 }
46
47 // Should lint for params too
48 pub fn rem_euclid_4(num: i32) -> i32 {
49     num.rem_euclid(4)
50 }
51
52 // Constant version came later, should still lint
53 pub const fn const_rem_euclid_4(num: i32) -> i32 {
54     num.rem_euclid(4)
55 }