Skip to content

Commit f8fd4ac

Browse files
committed
Make epsilon note spanless when comparing arrays
1 parent 1a7bddb commit f8fd4ac

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
@@ -391,8 +391,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
391391
),
392392
Applicability::HasPlaceholders, // snippet
393393
);
394+
db.span_note(expr.span, "`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
395+
} else {
396+
db.note("`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
394397
}
395-
db.span_note(expr.span, "`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
396398
});
397399
} else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) {
398400
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: `std::f32::EPSILON` and `std::f64::EPSILON` are available.
57-
--> $DIR/float_cmp.rs:98:5
58-
|
59-
LL | a1 == a2;
60-
| ^^^^^^^^
56+
= note: `std::f32::EPSILON` and `std::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)