]> git.lizzy.rs Git - rust.git/blob - tests/ui/float_cmp_const.rs
Auto merge of #4314 - chansuke:add-negation-to-is_empty, r=flip1995
[rust.git] / tests / ui / float_cmp_const.rs
1 #![warn(clippy::float_cmp_const)]
2 #![allow(clippy::float_cmp)]
3 #![allow(unused, clippy::no_effect, clippy::unnecessary_operation)]
4
5 const ONE: f32 = 1.0;
6 const TWO: f32 = 2.0;
7
8 fn eq_one(x: f32) -> bool {
9     if x.is_nan() {
10         false
11     } else {
12         x == ONE
13     } // no error, inside "eq" fn
14 }
15
16 fn main() {
17     // has errors
18     1f32 == ONE;
19     TWO == ONE;
20     TWO != ONE;
21     ONE + ONE == TWO;
22     let x = 1;
23     x as f32 == ONE;
24
25     let v = 0.9;
26     v == ONE;
27     v != ONE;
28
29     // no errors, lower than or greater than comparisons
30     v < ONE;
31     v > ONE;
32     v <= ONE;
33     v >= ONE;
34
35     // no errors, zero and infinity values
36     ONE != 0f32;
37     TWO == 0f32;
38     ONE != ::std::f32::INFINITY;
39     ONE == ::std::f32::NEG_INFINITY;
40
41     // no errors, but will warn clippy::float_cmp if '#![allow(float_cmp)]' above is removed
42     let w = 1.1;
43     v == w;
44     v != w;
45     v == 1.0;
46     v != 1.0;
47 }