mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-21 03:14:11 +00:00
Fix NAN comparison lint to use assoc NAN
This commit is contained in:
parent
d342cee787
commit
0b4ee9a649
@ -57,10 +57,9 @@ declare_clippy_lint! {
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// # use core::f32::NAN;
|
||||
/// # let x = 1.0;
|
||||
///
|
||||
/// if x == NAN { }
|
||||
/// if x == f32::NAN { }
|
||||
/// ```
|
||||
pub CMP_NAN,
|
||||
correctness,
|
||||
@ -457,7 +456,7 @@ fn check_nan(cx: &LateContext<'_, '_>, expr: &Expr<'_>, cmp_expr: &Expr<'_>) {
|
||||
cx,
|
||||
CMP_NAN,
|
||||
cmp_expr.span,
|
||||
"doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead",
|
||||
"doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
const NAN_F32: f32 = std::f32::NAN;
|
||||
const NAN_F64: f64 = std::f64::NAN;
|
||||
const NAN_F32: f32 = f32::NAN;
|
||||
const NAN_F64: f64 = f64::NAN;
|
||||
|
||||
#[warn(clippy::cmp_nan)]
|
||||
#[allow(clippy::float_cmp, clippy::no_effect, clippy::unnecessary_operation)]
|
||||
fn main() {
|
||||
let x = 5f32;
|
||||
x == std::f32::NAN;
|
||||
x != std::f32::NAN;
|
||||
x < std::f32::NAN;
|
||||
x > std::f32::NAN;
|
||||
x <= std::f32::NAN;
|
||||
x >= std::f32::NAN;
|
||||
x == f32::NAN;
|
||||
x != f32::NAN;
|
||||
x < f32::NAN;
|
||||
x > f32::NAN;
|
||||
x <= f32::NAN;
|
||||
x >= f32::NAN;
|
||||
x == NAN_F32;
|
||||
x != NAN_F32;
|
||||
x < NAN_F32;
|
||||
@ -19,12 +19,12 @@ fn main() {
|
||||
x >= NAN_F32;
|
||||
|
||||
let y = 0f64;
|
||||
y == std::f64::NAN;
|
||||
y != std::f64::NAN;
|
||||
y < std::f64::NAN;
|
||||
y > std::f64::NAN;
|
||||
y <= std::f64::NAN;
|
||||
y >= std::f64::NAN;
|
||||
y == f64::NAN;
|
||||
y != f64::NAN;
|
||||
y < f64::NAN;
|
||||
y > f64::NAN;
|
||||
y <= f64::NAN;
|
||||
y >= f64::NAN;
|
||||
y == NAN_F64;
|
||||
y != NAN_F64;
|
||||
y < NAN_F64;
|
||||
|
@ -1,144 +1,144 @@
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:8:5
|
||||
|
|
||||
LL | x == std::f32::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
LL | x == f32::NAN;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::cmp-nan` implied by `-D warnings`
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:9:5
|
||||
|
|
||||
LL | x != std::f32::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
LL | x != f32::NAN;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:10:5
|
||||
|
|
||||
LL | x < std::f32::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
LL | x < f32::NAN;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:11:5
|
||||
|
|
||||
LL | x > std::f32::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
LL | x > f32::NAN;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:12:5
|
||||
|
|
||||
LL | x <= std::f32::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
LL | x <= f32::NAN;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:13:5
|
||||
|
|
||||
LL | x >= std::f32::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
LL | x >= f32::NAN;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:14:5
|
||||
|
|
||||
LL | x == NAN_F32;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:15:5
|
||||
|
|
||||
LL | x != NAN_F32;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:16:5
|
||||
|
|
||||
LL | x < NAN_F32;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:17:5
|
||||
|
|
||||
LL | x > NAN_F32;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:18:5
|
||||
|
|
||||
LL | x <= NAN_F32;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:19:5
|
||||
|
|
||||
LL | x >= NAN_F32;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:22:5
|
||||
|
|
||||
LL | y == std::f64::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
LL | y == f64::NAN;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:23:5
|
||||
|
|
||||
LL | y != std::f64::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
LL | y != f64::NAN;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:24:5
|
||||
|
|
||||
LL | y < std::f64::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
LL | y < f64::NAN;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:25:5
|
||||
|
|
||||
LL | y > std::f64::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
LL | y > f64::NAN;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:26:5
|
||||
|
|
||||
LL | y <= std::f64::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
LL | y <= f64::NAN;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:27:5
|
||||
|
|
||||
LL | y >= std::f64::NAN;
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
LL | y >= f64::NAN;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:28:5
|
||||
|
|
||||
LL | y == NAN_F64;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:29:5
|
||||
|
|
||||
LL | y != NAN_F64;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:30:5
|
||||
|
|
||||
LL | y < NAN_F64;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:31:5
|
||||
|
|
||||
LL | y > NAN_F64;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:32:5
|
||||
|
|
||||
LL | y <= NAN_F64;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: doomed comparison with `NAN`, use `std::{f32,f64}::is_nan()` instead
|
||||
error: doomed comparison with `NAN`, use `{f32,f64}::is_nan()` instead
|
||||
--> $DIR/cmp_nan.rs:33:5
|
||||
|
|
||||
LL | y >= NAN_F64;
|
||||
|
Loading…
Reference in New Issue
Block a user