]> git.lizzy.rs Git - rust.git/blob - tests/ui/float_arithmetic.rs
Auto merge of #5323 - rabisg0:fix/5284, r=flip1995
[rust.git] / 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     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 }