blob: a5b63bed531b06c6fbd9f8bbf4cd88e8ad1addf4 (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#![feature(f128)]
#![feature(f16)]
#![warn(clippy::modulo_arithmetic)]
#![allow(clippy::no_effect, clippy::unnecessary_operation, clippy::modulo_one)]
fn main() {
// Lint when both sides are const and of the opposite sign
-1.6 % 2.1;
//~^ ERROR: you are using modulo operator on constants with different signs: `-1.600 %
//~| NOTE: double check for expected result especially when interoperating with differ
1.6 % -2.1;
//~^ ERROR: you are using modulo operator on constants with different signs: `1.600 %
//~| NOTE: double check for expected result especially when interoperating with differ
(1.1 - 2.3) % (1.1 + 2.3);
//~^ ERROR: you are using modulo operator on constants with different signs: `-1.200 %
//~| NOTE: double check for expected result especially when interoperating with differ
(1.1 + 2.3) % (1.1 - 2.3);
//~^ ERROR: you are using modulo operator on constants with different signs: `3.400 %
//~| NOTE: double check for expected result especially when interoperating with differ
// Lint on floating point numbers
let a_f16: f16 = -1.6;
let mut b_f16: f16 = 2.1;
a_f16 % b_f16;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
b_f16 % a_f16;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
b_f16 %= a_f16;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
// Lint on floating point numbers
let a_f32: f32 = -1.6;
let mut b_f32: f32 = 2.1;
a_f32 % b_f32;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
b_f32 % a_f32;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
b_f32 %= a_f32;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
let a_f64: f64 = -1.6;
let mut b_f64: f64 = 2.1;
a_f64 % b_f64;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
b_f64 % a_f64;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
b_f64 %= a_f64;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
let a_f128: f128 = -1.6;
let mut b_f128: f128 = 2.1;
a_f128 % b_f128;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
b_f128 % a_f128;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
b_f128 %= a_f128;
//~^ ERROR: you are using modulo operator on types that might have different signs
//~| NOTE: double check for expected result especially when interoperating with differ
// 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);
}
|