diff options
| author | Yusuf Raji <raji.yusuf234y@gmail.com> | 2024-05-05 23:26:29 +0200 |
|---|---|---|
| committer | Yusuf Raji <raji.yusuf234y@gmail.com> | 2024-05-06 00:04:00 +0200 |
| commit | c9ea0ae502aa5afe84ae528b697824412ebabf77 (patch) | |
| tree | fe0c304a1c7bd5b8ba642469d2e145ff52921ad1 /tests | |
| parent | 993d8ae2a7b26ac779fde923b2ce9ce35d7143a8 (diff) | |
| download | rust-c9ea0ae502aa5afe84ae528b697824412ebabf77.tar.gz rust-c9ea0ae502aa5afe84ae528b697824412ebabf77.zip | |
Lint while loops with float comparison
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/while_float.rs | 14 | ||||
| -rw-r--r-- | tests/ui/while_float.stderr | 20 |
2 files changed, 34 insertions, 0 deletions
diff --git a/tests/ui/while_float.rs b/tests/ui/while_float.rs new file mode 100644 index 00000000000..a3b0618948e --- /dev/null +++ b/tests/ui/while_float.rs @@ -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; + } +} diff --git a/tests/ui/while_float.stderr b/tests/ui/while_float.stderr new file mode 100644 index 00000000000..b8e934b97c6 --- /dev/null +++ b/tests/ui/while_float.stderr @@ -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 + |
