Skip to content

Commit f637c45

Browse files
committed
Indicate when arrays are compared in error message
1 parent 84ae3d8 commit f637c45

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

clippy_lints/src/misc.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,16 +369,31 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
369369
return;
370370
}
371371
}
372+
let is_comparing_arrays = is_array(cx, left) || is_array(cx, right);
372373
let (lint, msg) = if is_named_constant(cx, left) || is_named_constant(cx, right) {
373-
(FLOAT_CMP_CONST, "strict comparison of `f32` or `f64` constant")
374+
(
375+
FLOAT_CMP_CONST,
376+
if is_comparing_arrays {
377+
"strict comparison of `f32` or `f64` constant arrays"
378+
} else {
379+
"strict comparison of `f32` or `f64` constant"
380+
},
381+
)
374382
} else {
375-
(FLOAT_CMP, "strict comparison of `f32` or `f64`")
383+
(
384+
FLOAT_CMP,
385+
if is_comparing_arrays {
386+
"strict comparison of `f32` or `f64` arrays"
387+
} else {
388+
"strict comparison of `f32` or `f64`"
389+
},
390+
)
376391
};
377392
span_lint_and_then(cx, lint, expr.span, msg, |db| {
378393
let lhs = Sugg::hir(cx, left, "..");
379394
let rhs = Sugg::hir(cx, right, "..");
380395

381-
if !(is_array(cx, left) || is_array(cx, right)) {
396+
if !is_comparing_arrays {
382397
db.span_suggestion(
383398
expr.span,
384399
"consider comparing them within some error",

tests/ui/float_cmp.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ note: `f32::EPSILON` and `f64::EPSILON` are available.
4747
LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
4848
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4949

50-
error: strict comparison of `f32` or `f64`
50+
error: strict comparison of `f32` or `f64` arrays
5151
--> $DIR/float_cmp.rs:98:5
5252
|
5353
LL | a1 == a2;

tests/ui/float_cmp_const.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ note: `f32::EPSILON` and `f64::EPSILON` are available.
8383
LL | v != ONE;
8484
| ^^^^^^^^
8585

86-
error: strict comparison of `f32` or `f64` constant
86+
error: strict comparison of `f32` or `f64` constant arrays
8787
--> $DIR/float_cmp_const.rs:61:5
8888
|
8989
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;

0 commit comments

Comments
 (0)