]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/float_cmp.rs
iterate List by value
[rust.git] / tests / ui / float_cmp.rs
index b5c6a6449c2a45358e91e7749c3c00c29af10664..9fa0e5f5c079b5e8bf2b8a0e3f2929f87b45d809 100644 (file)
@@ -1,5 +1,11 @@
 #![warn(clippy::float_cmp)]
-#![allow(unused, clippy::no_effect, clippy::unnecessary_operation, clippy::cast_lossless)]
+#![allow(
+    unused,
+    clippy::no_effect,
+    clippy::unnecessary_operation,
+    clippy::cast_lossless,
+    clippy::many_single_char_names
+)]
 
 use std::ops::Add;
 
@@ -77,12 +83,20 @@ fn main() {
 
     assert_eq!(a, b); // no errors
 
+    const ZERO_ARRAY: [f32; 2] = [0.0, 0.0];
+    const NON_ZERO_ARRAY: [f32; 2] = [0.0, 0.1];
+
+    let i = 0;
+    let j = 1;
+
+    ZERO_ARRAY[i] == NON_ZERO_ARRAY[j]; // ok, because lhs is zero regardless of i
+    NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
+
     let a1: [f32; 1] = [0.0];
     let a2: [f32; 1] = [1.1];
 
-    assert_eq!(a1[0], a2[0]);
-
-    assert_eq!(&a1[0], &a2[0]);
+    a1 == a2;
+    a1[0] == a2[0];
 
     // no errors - comparing signums is ok
     let x32 = 3.21f32;