You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of rust-lang#11385 - markhuang1212:master, r=blyxyas
skip float_cmp check if lhs is a custom type
*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog: [`float_cmp`]: allow float eq comparison when lhs is a custom type that implements PartialEq<f32/f64>
If the lhs of a comparison is not float, it means there is a user implemented PartialEq, and the caller is invoking that custom version of `==`, instead of the default floating point equal comparison.
People may wrap f32 with a struct (say `MyF32`) and implement its PartialEq that will do the `is_close()` check, so that `MyF32` can be compared with either f32 or `MyF32`.
Copy file name to clipboardExpand all lines: tests/ui/float_cmp.stderr
+6-6
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
error: strict comparison of `f32` or `f64`
2
-
--> $DIR/float_cmp.rs:57:5
2
+
--> $DIR/float_cmp.rs:70:5
3
3
|
4
4
LL | ONE as f64 != 2.0;
5
5
| ^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(ONE as f64 - 2.0).abs() > error_margin`
@@ -8,39 +8,39 @@ LL | ONE as f64 != 2.0;
8
8
= note: `-D clippy::float-cmp` implied by `-D warnings`
9
9
10
10
error: strict comparison of `f32` or `f64`
11
-
--> $DIR/float_cmp.rs:64:5
11
+
--> $DIR/float_cmp.rs:77:5
12
12
|
13
13
LL | x == 1.0;
14
14
| ^^^^^^^^ help: consider comparing them within some margin of error: `(x - 1.0).abs() < error_margin`
15
15
|
16
16
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
17
17
18
18
error: strict comparison of `f32` or `f64`
19
-
--> $DIR/float_cmp.rs:69:5
19
+
--> $DIR/float_cmp.rs:82:5
20
20
|
21
21
LL | twice(x) != twice(ONE as f64);
22
22
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(twice(x) - twice(ONE as f64)).abs() > error_margin`
23
23
|
24
24
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
25
25
26
26
error: strict comparison of `f32` or `f64`
27
-
--> $DIR/float_cmp.rs:91:5
27
+
--> $DIR/float_cmp.rs:104:5
28
28
|
29
29
LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
30
30
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(NON_ZERO_ARRAY[i] - NON_ZERO_ARRAY[j]).abs() < error_margin`
31
31
|
32
32
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
33
33
34
34
error: strict comparison of `f32` or `f64` arrays
35
-
--> $DIR/float_cmp.rs:98:5
35
+
--> $DIR/float_cmp.rs:111:5
36
36
|
37
37
LL | a1 == a2;
38
38
| ^^^^^^^^
39
39
|
40
40
= note: `f32::EPSILON` and `f64::EPSILON` are available for the `error_margin`
41
41
42
42
error: strict comparison of `f32` or `f64`
43
-
--> $DIR/float_cmp.rs:101:5
43
+
--> $DIR/float_cmp.rs:114:5
44
44
|
45
45
LL | a1[0] == a2[0];
46
46
| ^^^^^^^^^^^^^^ help: consider comparing them within some margin of error: `(a1[0] - a2[0]).abs() < error_margin`
0 commit comments