Skip to content

Commit bce1293

Browse files
committed
Don't show comparison suggestion for arrays
1 parent 74f5090 commit bce1293

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

clippy_lints/src/misc.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
380380
let lhs = Sugg::hir(cx, left, "..");
381381
let rhs = Sugg::hir(cx, right, "..");
382382

383-
db.span_suggestion(
384-
expr.span,
385-
"consider comparing them within some error",
386-
format!(
387-
"({}).abs() {} error",
388-
lhs - rhs,
389-
if op == BinOpKind::Eq { '<' } else { '>' }
390-
),
391-
Applicability::HasPlaceholders, // snippet
392-
);
383+
if !(is_array(cx, left) || is_array(cx, right)) {
384+
db.span_suggestion(
385+
expr.span,
386+
"consider comparing them within some error",
387+
format!(
388+
"({}).abs() {} error",
389+
lhs - rhs,
390+
if op == BinOpKind::Eq { '<' } else { '>' }
391+
),
392+
Applicability::HasPlaceholders, // snippet
393+
);
394+
}
393395
db.span_note(expr.span, "`std::f32::EPSILON` and `std::f64::EPSILON` are available.");
394396
});
395397
} else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) {
@@ -515,6 +517,10 @@ fn is_float(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
515517
matches!(value, ty::Float(_))
516518
}
517519

520+
fn is_array(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
521+
matches!(&walk_ptrs_ty(cx.tables.expr_ty(expr)).kind, ty::Array(_, _))
522+
}
523+
518524
fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) {
519525
let (arg_ty, snip) = match expr.kind {
520526
ExprKind::MethodCall(.., ref args) if args.len() == 1 => {

0 commit comments

Comments
 (0)