Make suggestion give multiple alternatives

This commit is contained in:
Catherine 2023-07-02 11:43:05 -05:00
parent f12edfdb53
commit 5949f762bf
4 changed files with 117 additions and 65 deletions

View file

@ -1,37 +0,0 @@
//@run-rustfix
//@aux-build:proc_macros.rs:proc-macro
#![allow(clippy::needless_if, unused)]
#![warn(clippy::manual_is_infinite, clippy::manual_is_finite)]
#[macro_use]
extern crate proc_macros;
const INFINITE: f32 = f32::INFINITY;
const NEG_INFINITE: f32 = f32::NEG_INFINITY;
fn main() {
let x = 1.0f32;
if x.is_infinite() {}
if x.is_finite() {}
if x.is_infinite() {}
if x.is_finite() {}
let x = 1.0f64;
if x.is_infinite() {}
if x.is_finite() {}
// Don't lint
if x.is_infinite() {}
if x.is_finite() {}
// If they're doing it this way, they probably know what they're doing
if x.abs() < f64::INFINITY {}
external! {
let x = 1.0;
if x == f32::INFINITY || x == f32::NEG_INFINITY {}
if x != f32::INFINITY && x != f32::NEG_INFINITY {}
}
with_span! {
span
let x = 1.0;
if x == f32::INFINITY || x == f32::NEG_INFINITY {}
if x != f32::INFINITY && x != f32::NEG_INFINITY {}
}
}

View file

@ -1,4 +1,3 @@
//@run-rustfix
//@aux-build:proc_macros.rs:proc-macro
#![allow(clippy::needless_if, unused)]
#![warn(clippy::manual_is_infinite, clippy::manual_is_finite)]

View file

@ -1,42 +1,80 @@
error: manually checking if a float is infinite
--> $DIR/manual_float_methods.rs:14:8
--> $DIR/manual_float_methods.rs:13:8
|
LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_infinite()`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()`
|
= note: `-D clippy::manual-is-infinite` implied by `-D warnings`
error: manually checking if a float is finite
--> $DIR/manual_float_methods.rs:15:8
--> $DIR/manual_float_methods.rs:14:8
|
LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_finite()`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::manual-is-finite` implied by `-D warnings`
help: use the dedicated method instead
|
LL | if x.is_finite() {}
| ~~~~~~~~~~~~~
help: this will alter how it handles NaN; if that is a problem, use instead
|
LL | if x.is_finite() || x.is_nan() {}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: or, for conciseness
|
LL | if !x.is_infinite() {}
| ~~~~~~~~~~~~~~~~
error: manually checking if a float is infinite
--> $DIR/manual_float_methods.rs:16:8
--> $DIR/manual_float_methods.rs:15:8
|
LL | if x == INFINITE || x == NEG_INFINITE {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_infinite()`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()`
error: manually checking if a float is finite
--> $DIR/manual_float_methods.rs:17:8
--> $DIR/manual_float_methods.rs:16:8
|
LL | if x != INFINITE && x != NEG_INFINITE {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_finite()`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use the dedicated method instead
|
LL | if x.is_finite() {}
| ~~~~~~~~~~~~~
help: this will alter how it handles NaN; if that is a problem, use instead
|
LL | if x.is_finite() || x.is_nan() {}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: or, for conciseness
|
LL | if !x.is_infinite() {}
| ~~~~~~~~~~~~~~~~
error: manually checking if a float is infinite
--> $DIR/manual_float_methods.rs:19:8
--> $DIR/manual_float_methods.rs:18:8
|
LL | if x == f64::INFINITY || x == f64::NEG_INFINITY {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_infinite()`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the dedicated method instead: `x.is_infinite()`
error: manually checking if a float is finite
--> $DIR/manual_float_methods.rs:20:8
--> $DIR/manual_float_methods.rs:19:8
|
LL | if x != f64::INFINITY && x != f64::NEG_INFINITY {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_finite()`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use the dedicated method instead
|
LL | if x.is_finite() {}
| ~~~~~~~~~~~~~
help: this will alter how it handles NaN; if that is a problem, use instead
|
LL | if x.is_finite() || x.is_nan() {}
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: or, for conciseness
|
LL | if !x.is_infinite() {}
| ~~~~~~~~~~~~~~~~
error: aborting due to 6 previous errors