Skip to content

Commit 0d00eaf

Browse files
briankabiromarcin-serwin
authored andcommitted
Add tests for float in array comparison
1 parent d440935 commit 0d00eaf

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

tests/ui/float_cmp.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ fn main() {
7777

7878
assert_eq!(a, b); // no errors
7979

80+
let a1: [f32; 1] = [0.0];
81+
let a2: [f32; 1] = [1.1];
82+
83+
assert_eq!(a1[0], a2[0]);
84+
85+
assert_eq!(&a1[0], &a2[0]);
86+
8087
// no errors - comparing signums is ok
8188
let x32 = 3.21f32;
8289
1.23f32.signum() == x32.signum();

tests/ui/float_cmp.stderr

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,31 @@ note: `f32::EPSILON` and `f64::EPSILON` are available.
3535
LL | twice(x) != twice(ONE as f64);
3636
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3737

38-
error: aborting due to 3 previous errors
38+
error: strict comparison of f32 or f64
39+
--> $DIR/float_cmp.rs:83:5
40+
|
41+
LL | assert_eq!(a1[0], a2[0]);
42+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
43+
|
44+
note: std::f32::EPSILON and std::f64::EPSILON are available.
45+
--> $DIR/float_cmp.rs:83:5
46+
|
47+
LL | assert_eq!(a1[0], a2[0]);
48+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
49+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
50+
51+
error: strict comparison of f32 or f64
52+
--> $DIR/float_cmp.rs:85:5
53+
|
54+
LL | assert_eq!(&a1[0], &a2[0]);
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
|
57+
note: std::f32::EPSILON and std::f64::EPSILON are available.
58+
--> $DIR/float_cmp.rs:85:5
59+
|
60+
LL | assert_eq!(&a1[0], &a2[0]);
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
62+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
63+
64+
error: aborting due to 5 previous errors
3965

0 commit comments

Comments
 (0)