Skip to content

Commit 84ae3d8

Browse files
committed
Make epsilon note spanless when comparing arrays
1 parent c7b5e30 commit 84ae3d8

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

clippy_lints/src/misc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
389389
),
390390
Applicability::HasPlaceholders, // snippet
391391
);
392+
db.span_note(expr.span, "`f32::EPSILON` and `f64::EPSILON` are available.");
393+
} else {
394+
db.note("`f32::EPSILON` and `f64::EPSILON` are available.");
392395
}
393-
db.span_note(expr.span, "`f32::EPSILON` and `f64::EPSILON` are available.");
394396
});
395397
} else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) {
396398
span_lint(cx, MODULO_ONE, expr.span, "any number modulo 1 will be 0");

tests/ui/float_cmp.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ error: strict comparison of `f32` or `f64`
5353
LL | a1 == a2;
5454
| ^^^^^^^^
5555
|
56-
note: `f32::EPSILON` and `f64::EPSILON` are available.
57-
--> $DIR/float_cmp.rs:98:5
58-
|
59-
LL | a1 == a2;
60-
| ^^^^^^^^
56+
= note: `f32::EPSILON` and `f64::EPSILON` are available.
6157

6258
error: strict comparison of `f32` or `f64`
6359
--> $DIR/float_cmp.rs:99:5

tests/ui/float_cmp_const.stderr

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ error: strict comparison of `f32` or `f64` constant
8989
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
9090
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9191
|
92-
note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
93-
--> $DIR/float_cmp_const.rs:61:5
94-
|
95-
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
96-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
92+
= note: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
9793

9894
error: aborting due to 8 previous errors
9995

0 commit comments

Comments
 (0)