Skip to content

Commit ec1dcde

Browse files
committed
tests: arithmetic: split into integer_arithmetic and float_arithmetic files.
1 parent f041dcd commit ec1dcde

5 files changed

+266
-255
lines changed

tests/ui/arithmetic.stderr

-211
This file was deleted.

tests/ui/float_arithmetic.rs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#![warn(clippy::integer_arithmetic, clippy::float_arithmetic)]
2+
#![allow(
3+
unused,
4+
clippy::shadow_reuse,
5+
clippy::shadow_unrelated,
6+
clippy::no_effect,
7+
clippy::unnecessary_operation,
8+
clippy::op_ref,
9+
clippy::trivially_copy_pass_by_ref
10+
)]
11+
12+
#[rustfmt::skip]
13+
fn main() {
14+
let mut f = 1.0f32;
15+
16+
f * 2.0;
17+
18+
1.0 + f;
19+
f * 2.0;
20+
f / 2.0;
21+
f - 2.0 * 4.2;
22+
-f;
23+
24+
f += 1.0;
25+
f -= 1.0;
26+
f *= 2.0;
27+
f /= 2.0;
28+
}
29+
30+
// also warn about floating point arith with references involved
31+
32+
pub fn float_arith_ref() {
33+
3.1_f32 + &1.2_f32;
34+
&3.4_f32 + 1.5_f32;
35+
&3.5_f32 + &1.3_f32;
36+
}
37+
38+
pub fn float_foo(f: &f32) -> f32 {
39+
let a = 5.1;
40+
a + f
41+
}
42+
43+
pub fn float_bar(f1: &f32, f2: &f32) -> f32 {
44+
f1 + f2
45+
}
46+
47+
pub fn float_baz(f1: f32, f2: &f32) -> f32 {
48+
f1 + f2
49+
}
50+
51+
pub fn float_qux(f1: f32, f2: f32) -> f32 {
52+
(&f1 + &f2)
53+
}

tests/ui/float_arithmetic.stderr

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
error: floating-point arithmetic detected
2+
--> $DIR/float_arithmetic.rs:16:5
3+
|
4+
LL | f * 2.0;
5+
| ^^^^^^^
6+
|
7+
= note: `-D clippy::float-arithmetic` implied by `-D warnings`
8+
9+
error: floating-point arithmetic detected
10+
--> $DIR/float_arithmetic.rs:18:5
11+
|
12+
LL | 1.0 + f;
13+
| ^^^^^^^
14+
15+
error: floating-point arithmetic detected
16+
--> $DIR/float_arithmetic.rs:19:5
17+
|
18+
LL | f * 2.0;
19+
| ^^^^^^^
20+
21+
error: floating-point arithmetic detected
22+
--> $DIR/float_arithmetic.rs:20:5
23+
|
24+
LL | f / 2.0;
25+
| ^^^^^^^
26+
27+
error: floating-point arithmetic detected
28+
--> $DIR/float_arithmetic.rs:21:5
29+
|
30+
LL | f - 2.0 * 4.2;
31+
| ^^^^^^^^^^^^^
32+
33+
error: floating-point arithmetic detected
34+
--> $DIR/float_arithmetic.rs:22:5
35+
|
36+
LL | -f;
37+
| ^^
38+
39+
error: floating-point arithmetic detected
40+
--> $DIR/float_arithmetic.rs:24:5
41+
|
42+
LL | f += 1.0;
43+
| ^^^^^^^^
44+
45+
error: floating-point arithmetic detected
46+
--> $DIR/float_arithmetic.rs:25:5
47+
|
48+
LL | f -= 1.0;
49+
| ^^^^^^^^
50+
51+
error: floating-point arithmetic detected
52+
--> $DIR/float_arithmetic.rs:26:5
53+
|
54+
LL | f *= 2.0;
55+
| ^^^^^^^^
56+
57+
error: floating-point arithmetic detected
58+
--> $DIR/float_arithmetic.rs:27:5
59+
|
60+
LL | f /= 2.0;
61+
| ^^^^^^^^
62+
63+
error: floating-point arithmetic detected
64+
--> $DIR/float_arithmetic.rs:33:5
65+
|
66+
LL | 3.1_f32 + &1.2_f32;
67+
| ^^^^^^^^^^^^^^^^^^
68+
69+
error: floating-point arithmetic detected
70+
--> $DIR/float_arithmetic.rs:34:5
71+
|
72+
LL | &3.4_f32 + 1.5_f32;
73+
| ^^^^^^^^^^^^^^^^^^
74+
75+
error: floating-point arithmetic detected
76+
--> $DIR/float_arithmetic.rs:35:5
77+
|
78+
LL | &3.5_f32 + &1.3_f32;
79+
| ^^^^^^^^^^^^^^^^^^^
80+
81+
error: floating-point arithmetic detected
82+
--> $DIR/float_arithmetic.rs:40:5
83+
|
84+
LL | a + f
85+
| ^^^^^
86+
87+
error: floating-point arithmetic detected
88+
--> $DIR/float_arithmetic.rs:44:5
89+
|
90+
LL | f1 + f2
91+
| ^^^^^^^
92+
93+
error: floating-point arithmetic detected
94+
--> $DIR/float_arithmetic.rs:48:5
95+
|
96+
LL | f1 + f2
97+
| ^^^^^^^
98+
99+
error: floating-point arithmetic detected
100+
--> $DIR/float_arithmetic.rs:52:5
101+
|
102+
LL | (&f1 + &f2)
103+
| ^^^^^^^^^^^
104+
105+
error: aborting due to 17 previous errors
106+

0 commit comments

Comments
 (0)