mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Indicate when arrays are compared in error message
This commit is contained in:
parent
84ae3d8bc8
commit
f637c45f8b
3 changed files with 20 additions and 5 deletions
|
@ -369,16 +369,31 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
return;
|
||||
}
|
||||
}
|
||||
let is_comparing_arrays = is_array(cx, left) || is_array(cx, right);
|
||||
let (lint, msg) = if is_named_constant(cx, left) || is_named_constant(cx, right) {
|
||||
(FLOAT_CMP_CONST, "strict comparison of `f32` or `f64` constant")
|
||||
(
|
||||
FLOAT_CMP_CONST,
|
||||
if is_comparing_arrays {
|
||||
"strict comparison of `f32` or `f64` constant arrays"
|
||||
} else {
|
||||
"strict comparison of `f32` or `f64` constant"
|
||||
},
|
||||
)
|
||||
} else {
|
||||
(FLOAT_CMP, "strict comparison of `f32` or `f64`")
|
||||
(
|
||||
FLOAT_CMP,
|
||||
if is_comparing_arrays {
|
||||
"strict comparison of `f32` or `f64` arrays"
|
||||
} else {
|
||||
"strict comparison of `f32` or `f64`"
|
||||
},
|
||||
)
|
||||
};
|
||||
span_lint_and_then(cx, lint, expr.span, msg, |db| {
|
||||
let lhs = Sugg::hir(cx, left, "..");
|
||||
let rhs = Sugg::hir(cx, right, "..");
|
||||
|
||||
if !(is_array(cx, left) || is_array(cx, right)) {
|
||||
if !is_comparing_arrays {
|
||||
db.span_suggestion(
|
||||
expr.span,
|
||||
"consider comparing them within some error",
|
||||
|
|
|
@ -47,7 +47,7 @@ note: `f32::EPSILON` and `f64::EPSILON` are available.
|
|||
LL | NON_ZERO_ARRAY[i] == NON_ZERO_ARRAY[j];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: strict comparison of `f32` or `f64`
|
||||
error: strict comparison of `f32` or `f64` arrays
|
||||
--> $DIR/float_cmp.rs:98:5
|
||||
|
|
||||
LL | a1 == a2;
|
||||
|
|
|
@ -83,7 +83,7 @@ note: `f32::EPSILON` and `f64::EPSILON` are available.
|
|||
LL | v != ONE;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: strict comparison of `f32` or `f64` constant
|
||||
error: strict comparison of `f32` or `f64` constant arrays
|
||||
--> $DIR/float_cmp_const.rs:61:5
|
||||
|
|
||||
LL | NON_ZERO_ARRAY == NON_ZERO_ARRAY2;
|
||||
|
|
Loading…
Reference in a new issue