]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/float_arithmetic.rs
Rollup merge of #102454 - chenyukang:fix-102396-missing-parentheses, r=lcnr
[rust.git] / src / tools / clippy / tests / ui / float_arithmetic.rs
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 )]
10
11 #[rustfmt::skip]
12 fn main() {
13     let mut f = 1.0f32;
14
15     f * 2.0;
16
17     1.0 + f;
18     f * 2.0;
19     f / 2.0;
20     f - 2.0 * 4.2;
21     -f;
22
23     f += 1.0;
24     f -= 1.0;
25     f *= 2.0;
26     f /= 2.0;
27 }
28
29 // also warn about floating point arith with references involved
30
31 pub fn float_arith_ref() {
32     3.1_f32 + &1.2_f32;
33     &3.4_f32 + 1.5_f32;
34     &3.5_f32 + &1.3_f32;
35 }
36
37 pub fn float_foo(f: &f32) -> f32 {
38     let a = 5.1;
39     a + f
40 }
41
42 pub fn float_bar(f1: &f32, f2: &f32) -> f32 {
43     f1 + f2
44 }
45
46 pub fn float_baz(f1: f32, f2: &f32) -> f32 {
47     f1 + f2
48 }
49
50 pub fn float_qux(f1: f32, f2: f32) -> f32 {
51     (&f1 + &f2)
52 }