Skip to content

Commit e7c9d64

Browse files
committed
Fix NAN comparison lint to use assoc NAN
1 parent 7907abe commit e7c9d64

File tree

3 files changed

+64
-65
lines changed

3 files changed

+64
-65
lines changed

clippy_lints/src/misc.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ declare_clippy_lint! {
5757
///
5858
/// **Example:**
5959
/// ```rust
60-
/// # use core::f32::NAN;
6160
/// # let x = 1.0;
6261
///
63-
/// if x == NAN { }
62+
/// if x == f32::NAN { }
6463
/// ```
6564
pub CMP_NAN,
6665
correctness,
@@ -457,7 +456,7 @@ fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) {
457456
cx,
458457
CMP_NAN,
459458
cmp_expr.span,
460-
"doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead",
459+
"doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead",
461460
);
462461
}
463462
}

tests/ui/cmp_nan.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
const NAN_F32: f32 = std::f32::NAN;
2-
const NAN_F64: f64 = std::f64::NAN;
1+
const NAN_F32: f32 = f32::NAN;
2+
const NAN_F64: f64 = f64::NAN;
33

44
#[warn(clippy::cmp_nan)]
55
#[allow(clippy::float_cmp, clippy::no_effect, clippy::unnecessary_operation)]
66
fn main() {
77
let x = 5f32;
8-
x == std::f32::NAN;
9-
x != std::f32::NAN;
10-
x < std::f32::NAN;
11-
x > std::f32::NAN;
12-
x <= std::f32::NAN;
13-
x >= std::f32::NAN;
8+
x == f32::NAN;
9+
x != f32::NAN;
10+
x < f32::NAN;
11+
x > f32::NAN;
12+
x <= f32::NAN;
13+
x >= f32::NAN;
1414
x == NAN_F32;
1515
x != NAN_F32;
1616
x < NAN_F32;
@@ -19,12 +19,12 @@ fn main() {
1919
x >= NAN_F32;
2020

2121
let y = 0f64;
22-
y == std::f64::NAN;
23-
y != std::f64::NAN;
24-
y < std::f64::NAN;
25-
y > std::f64::NAN;
26-
y <= std::f64::NAN;
27-
y >= std::f64::NAN;
22+
y == f64::NAN;
23+
y != f64::NAN;
24+
y < f64::NAN;
25+
y > f64::NAN;
26+
y <= f64::NAN;
27+
y >= f64::NAN;
2828
y == NAN_F64;
2929
y != NAN_F64;
3030
y < NAN_F64;

tests/ui/cmp_nan.stderr

+48-48
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,144 @@
1-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
1+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
22
--> $DIR/cmp_nan.rs:8:5
33
|
4-
LL | x == std::f32::NAN;
5-
| ^^^^^^^^^^^^^^^^^^
4+
LL | x == f32::NAN;
5+
| ^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::cmp-nan` implied by `-D warnings`
88

9-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
9+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
1010
--> $DIR/cmp_nan.rs:9:5
1111
|
12-
LL | x != std::f32::NAN;
13-
| ^^^^^^^^^^^^^^^^^^
12+
LL | x != f32::NAN;
13+
| ^^^^^^^^^^^^^
1414

15-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
15+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
1616
--> $DIR/cmp_nan.rs:10:5
1717
|
18-
LL | x < std::f32::NAN;
19-
| ^^^^^^^^^^^^^^^^^
18+
LL | x < f32::NAN;
19+
| ^^^^^^^^^^^^
2020

21-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
21+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
2222
--> $DIR/cmp_nan.rs:11:5
2323
|
24-
LL | x > std::f32::NAN;
25-
| ^^^^^^^^^^^^^^^^^
24+
LL | x > f32::NAN;
25+
| ^^^^^^^^^^^^
2626

27-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
27+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
2828
--> $DIR/cmp_nan.rs:12:5
2929
|
30-
LL | x <= std::f32::NAN;
31-
| ^^^^^^^^^^^^^^^^^^
30+
LL | x <= f32::NAN;
31+
| ^^^^^^^^^^^^^
3232

33-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
33+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
3434
--> $DIR/cmp_nan.rs:13:5
3535
|
36-
LL | x >= std::f32::NAN;
37-
| ^^^^^^^^^^^^^^^^^^
36+
LL | x >= f32::NAN;
37+
| ^^^^^^^^^^^^^
3838

39-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
39+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
4040
--> $DIR/cmp_nan.rs:14:5
4141
|
4242
LL | x == NAN_F32;
4343
| ^^^^^^^^^^^^
4444

45-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
45+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
4646
--> $DIR/cmp_nan.rs:15:5
4747
|
4848
LL | x != NAN_F32;
4949
| ^^^^^^^^^^^^
5050

51-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
51+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
5252
--> $DIR/cmp_nan.rs:16:5
5353
|
5454
LL | x < NAN_F32;
5555
| ^^^^^^^^^^^
5656

57-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
57+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
5858
--> $DIR/cmp_nan.rs:17:5
5959
|
6060
LL | x > NAN_F32;
6161
| ^^^^^^^^^^^
6262

63-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
63+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
6464
--> $DIR/cmp_nan.rs:18:5
6565
|
6666
LL | x <= NAN_F32;
6767
| ^^^^^^^^^^^^
6868

69-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
69+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
7070
--> $DIR/cmp_nan.rs:19:5
7171
|
7272
LL | x >= NAN_F32;
7373
| ^^^^^^^^^^^^
7474

75-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
75+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
7676
--> $DIR/cmp_nan.rs:22:5
7777
|
78-
LL | y == std::f64::NAN;
79-
| ^^^^^^^^^^^^^^^^^^
78+
LL | y == f64::NAN;
79+
| ^^^^^^^^^^^^^
8080

81-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
81+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
8282
--> $DIR/cmp_nan.rs:23:5
8383
|
84-
LL | y != std::f64::NAN;
85-
| ^^^^^^^^^^^^^^^^^^
84+
LL | y != f64::NAN;
85+
| ^^^^^^^^^^^^^
8686

87-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
87+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
8888
--> $DIR/cmp_nan.rs:24:5
8989
|
90-
LL | y < std::f64::NAN;
91-
| ^^^^^^^^^^^^^^^^^
90+
LL | y < f64::NAN;
91+
| ^^^^^^^^^^^^
9292

93-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
93+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
9494
--> $DIR/cmp_nan.rs:25:5
9595
|
96-
LL | y > std::f64::NAN;
97-
| ^^^^^^^^^^^^^^^^^
96+
LL | y > f64::NAN;
97+
| ^^^^^^^^^^^^
9898

99-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
99+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
100100
--> $DIR/cmp_nan.rs:26:5
101101
|
102-
LL | y <= std::f64::NAN;
103-
| ^^^^^^^^^^^^^^^^^^
102+
LL | y <= f64::NAN;
103+
| ^^^^^^^^^^^^^
104104

105-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
105+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
106106
--> $DIR/cmp_nan.rs:27:5
107107
|
108-
LL | y >= std::f64::NAN;
109-
| ^^^^^^^^^^^^^^^^^^
108+
LL | y >= f64::NAN;
109+
| ^^^^^^^^^^^^^
110110

111-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
111+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
112112
--> $DIR/cmp_nan.rs:28:5
113113
|
114114
LL | y == NAN_F64;
115115
| ^^^^^^^^^^^^
116116

117-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
117+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
118118
--> $DIR/cmp_nan.rs:29:5
119119
|
120120
LL | y != NAN_F64;
121121
| ^^^^^^^^^^^^
122122

123-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
123+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
124124
--> $DIR/cmp_nan.rs:30:5
125125
|
126126
LL | y < NAN_F64;
127127
| ^^^^^^^^^^^
128128

129-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
129+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
130130
--> $DIR/cmp_nan.rs:31:5
131131
|
132132
LL | y > NAN_F64;
133133
| ^^^^^^^^^^^
134134

135-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
135+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
136136
--> $DIR/cmp_nan.rs:32:5
137137
|
138138
LL | y <= NAN_F64;
139139
| ^^^^^^^^^^^^
140140

141-
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
141+
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
142142
--> $DIR/cmp_nan.rs:33:5
143143
|
144144
LL | y >= NAN_F64;

0 commit comments

Comments
 (0)