manual_float_methods
This commit is contained in:
parent
dd8e44c5a2
commit
f12edfdb53
8 changed files with 239 additions and 0 deletions
37
tests/ui/manual_float_methods.fixed
Normal file
37
tests/ui/manual_float_methods.fixed
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//@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 {}
|
||||
}
|
||||
}
|
||||
37
tests/ui/manual_float_methods.rs
Normal file
37
tests/ui/manual_float_methods.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//@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 == f32::INFINITY || x == f32::NEG_INFINITY {}
|
||||
if x != f32::INFINITY && x != f32::NEG_INFINITY {}
|
||||
if x == INFINITE || x == NEG_INFINITE {}
|
||||
if x != INFINITE && x != NEG_INFINITE {}
|
||||
let x = 1.0f64;
|
||||
if x == f64::INFINITY || x == f64::NEG_INFINITY {}
|
||||
if x != f64::INFINITY && x != f64::NEG_INFINITY {}
|
||||
// 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 {}
|
||||
}
|
||||
}
|
||||
42
tests/ui/manual_float_methods.stderr
Normal file
42
tests/ui/manual_float_methods.stderr
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
error: manually checking if a float is infinite
|
||||
--> $DIR/manual_float_methods.rs:14:8
|
||||
|
|
||||
LL | if x == f32::INFINITY || x == f32::NEG_INFINITY {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `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
|
||||
|
|
||||
LL | if x != f32::INFINITY && x != f32::NEG_INFINITY {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_finite()`
|
||||
|
|
||||
= note: `-D clippy::manual-is-finite` implied by `-D warnings`
|
||||
|
||||
error: manually checking if a float is infinite
|
||||
--> $DIR/manual_float_methods.rs:16:8
|
||||
|
|
||||
LL | if x == INFINITE || x == NEG_INFINITE {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_infinite()`
|
||||
|
||||
error: manually checking if a float is finite
|
||||
--> $DIR/manual_float_methods.rs:17:8
|
||||
|
|
||||
LL | if x != INFINITE && x != NEG_INFINITE {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_finite()`
|
||||
|
||||
error: manually checking if a float is infinite
|
||||
--> $DIR/manual_float_methods.rs:19:8
|
||||
|
|
||||
LL | if x == f64::INFINITY || x == f64::NEG_INFINITY {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_infinite()`
|
||||
|
||||
error: manually checking if a float is finite
|
||||
--> $DIR/manual_float_methods.rs:20:8
|
||||
|
|
||||
LL | if x != f64::INFINITY && x != f64::NEG_INFINITY {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_finite()`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue