2019-12-26 12:34:55 +00:00
|
|
|
#![warn(clippy::modulo_arithmetic)]
|
2021-09-27 22:19:33 +00:00
|
|
|
#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::modulo_one)]
|
2019-12-26 12:34:55 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Lint when both sides are const and of the opposite sign
|
|
|
|
-1.6 % 2.1;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `-1.600 %
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
1.6 % -2.1;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `1.600 %
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
(1.1 - 2.3) % (1.1 + 2.3);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `-1.200 %
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
(1.1 + 2.3) % (1.1 - 2.3);
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on constants with different signs: `3.400 %
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
|
|
|
|
// Lint on floating point numbers
|
|
|
|
let a_f32: f32 = -1.6;
|
|
|
|
let mut b_f32: f32 = 2.1;
|
|
|
|
a_f32 % b_f32;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on types that might have different signs
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
b_f32 % a_f32;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on types that might have different signs
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
b_f32 %= a_f32;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on types that might have different signs
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
|
|
|
|
let a_f64: f64 = -1.6;
|
|
|
|
let mut b_f64: f64 = 2.1;
|
|
|
|
a_f64 % b_f64;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on types that might have different signs
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
b_f64 % a_f64;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on types that might have different signs
|
|
|
|
//~| NOTE: double check for expected result especially when interoperating with differ
|
2019-12-26 12:34:55 +00:00
|
|
|
b_f64 %= a_f64;
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: you are using modulo operator on types that might have different signs
|
|
|
|
//~| 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.6 % 2.1;
|
|
|
|
-1.6 % -2.1;
|
|
|
|
(1.1 + 2.3) % (-1.1 + 2.3);
|
|
|
|
(-1.1 - 2.3) % (1.1 - 2.3);
|
|
|
|
}
|