Auto merge of #12765 - yusufraji:while-float, r=llogiq
Add new lint `while_float` This PR adds a nursery lint that checks for while loops comparing floating point values. changelog: ``` changelog: [`while_float`]: Checks for while loops comparing floating point values. ``` Fixes #758
This commit is contained in:
commit
2efebd2f0c
6 changed files with 92 additions and 0 deletions
14
tests/ui/while_float.rs
Normal file
14
tests/ui/while_float.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#[deny(clippy::while_float)]
|
||||
fn main() {
|
||||
let mut x = 0.0_f32;
|
||||
while x < 42.0_f32 {
|
||||
x += 0.5;
|
||||
}
|
||||
while x < 42.0 {
|
||||
x += 1.0;
|
||||
}
|
||||
let mut x = 0;
|
||||
while x < 42 {
|
||||
x += 1;
|
||||
}
|
||||
}
|
||||
20
tests/ui/while_float.stderr
Normal file
20
tests/ui/while_float.stderr
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
error: while condition comparing floats
|
||||
--> tests/ui/while_float.rs:4:11
|
||||
|
|
||||
LL | while x < 42.0_f32 {
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> tests/ui/while_float.rs:1:8
|
||||
|
|
||||
LL | #[deny(clippy::while_float)]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: while condition comparing floats
|
||||
--> tests/ui/while_float.rs:7:11
|
||||
|
|
||||
LL | while x < 42.0 {
|
||||
| ^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue