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