about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-05-21 11:36:31 +0000
committerbors <bors@rust-lang.org>2024-05-21 11:36:31 +0000
commit2efebd2f0c03dabbe5c3ad7b4ebfbd99238d1fb2 (patch)
treecadf470d2c114545c2b5c44a89ac0c73f89478b3 /tests
parent0b1bf37722519e78d92c01118fde228e7ea9eb17 (diff)
parentcb3fcbbcfe3d92ae822f5fba402dbb3d48f30470 (diff)
downloadrust-2efebd2f0c03dabbe5c3ad7b4ebfbd99238d1fb2.tar.gz
rust-2efebd2f0c03dabbe5c3ad7b4ebfbd99238d1fb2.zip
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
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/while_float.rs14
-rw-r--r--tests/ui/while_float.stderr20
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
+