about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarcin Serwin <toxyxer@gmail.com>2020-03-20 11:54:04 +0100
committerMarcin Serwin <toxyxer@gmail.com>2020-04-09 08:08:36 +0200
commitc7b5e30423169f7de0e1874c018f47ba4f63d79e (patch)
tree2c1dbd0f9e39cbce7e4be3edc8f17b6671f453de
parent3c738b22869c50120eb8b7806311110ebf8fa870 (diff)
downloadrust-c7b5e30423169f7de0e1874c018f47ba4f63d79e.tar.gz
rust-c7b5e30423169f7de0e1874c018f47ba4f63d79e.zip
Add float cmp const tests for arrays
-rw-r--r--tests/ui/float_cmp_const.rs13
-rw-r--r--tests/ui/float_cmp_const.stderr14
2 files changed, 26 insertions, 1 deletions
diff --git a/tests/ui/float_cmp_const.rs b/tests/ui/float_cmp_const.rs
index a338040e19b..dfc025558a2 100644
--- a/tests/ui/float_cmp_const.rs
+++ b/tests/ui/float_cmp_const.rs
@@ -46,4 +46,17 @@ fn main() {
     v != w;
     v == 1.0;
     v != 1.0;
+
+    const ZERO_ARRAY: [f32; 3] = [0.0, 0.0, 0.0];
+    const ZERO_INF_ARRAY: [f32; 3] = [0.0, ::std::f32::INFINITY, ::std::f32::NEG_INFINITY];
+    const NON_ZERO_ARRAY: [f32; 3] = [0.0, 0.1, 0.2];
+    const NON_ZERO_ARRAY2: [f32; 3] = [0.2, 0.1, 0.0];
+
+    // no errors, zero and infinity values
+    NON_ZERO_ARRAY[0] == NON_ZERO_ARRAY2[1]; // lhs is 0.0
+    ZERO_ARRAY == NON_ZERO_ARRAY; // lhs is all zeros
+    ZERO_INF_ARRAY == NON_ZERO_ARRAY; // lhs is all zeros or infinities
+
+    // has errors
+    NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
 }
diff --git a/tests/ui/float_cmp_const.stderr b/tests/ui/float_cmp_const.stderr
index 2dc43cf4e5f..da4b0b937a8 100644
--- a/tests/ui/float_cmp_const.stderr
+++ b/tests/ui/float_cmp_const.stderr
@@ -83,5 +83,17 @@ note: `f32::EPSILON` and `f64::EPSILON` are available.
 LL |     v != ONE;
    |     ^^^^^^^^
 
-error: aborting due to 7 previous errors
+error: strict comparison of `f32` or `f64` constant
+  --> $DIR/float_cmp_const.rs:61:5
+   |
+LL |     NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
+  --> $DIR/float_cmp_const.rs:61:5
+   |
+LL |     NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 8 previous errors