2019-12-26 12:34:55 +00:00
|
|
|
#![warn(clippy::modulo_arithmetic)]
|
2022-03-11 03:31:17 +00:00
|
|
|
#![allow(
|
|
|
|
clippy::no_effect,
|
|
|
|
clippy::unnecessary_operation,
|
|
|
|
clippy::modulo_one,
|
|
|
|
clippy::identity_op
|
|
|
|
)]
|
2019-12-26 12:34:55 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Lint when both sides are const and of the opposite sign
|
|
|
|
-1 % 2;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
1 % -2;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
(1 - 2) % (1 + 2);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 3`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
(1 + 2) % (1 - 2);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `3 % -1`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
35 * (7 - 4 * 2) % (-500 * -600);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `-35 % 30
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
|
|
|
|
-1i8 % 2i8;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
1i8 % -2i8;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
-1i16 % 2i16;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
1i16 % -2i16;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
-1i32 % 2i32;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
1i32 % -2i32;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
-1i64 % 2i64;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
1i64 % -2i64;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
-1i128 % 2i128;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
1i128 % -2i128;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
-1isize % 2isize;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `-1 % 2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
1isize % -2isize;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `1 % -2`
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
|
|
|
|
// No lint when both sides are const and of the same sign
|
|
|
|
1 % 2;
|
|
|
|
-1 % -2;
|
|
|
|
(1 + 2) % (-1 + 2);
|
|
|
|
(-1 - 2) % (1 - 2);
|
|
|
|
|
|
|
|
1u8 % 2u8;
|
|
|
|
1u16 % 2u16;
|
|
|
|
1u32 % 2u32;
|
|
|
|
1u64 % 2u64;
|
|
|
|
1u128 % 2u128;
|
|
|
|
1usize % 2usize;
|
|
|
|
}
|