mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Don't show comparison suggestion for arrays
This commit is contained in:
parent
bcbb9d9acb
commit
1bab67c72b
1 changed files with 16 additions and 10 deletions
|
@ -378,16 +378,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
|
|||
let lhs = Sugg::hir(cx, left, "..");
|
||||
let rhs = Sugg::hir(cx, right, "..");
|
||||
|
||||
db.span_suggestion(
|
||||
expr.span,
|
||||
"consider comparing them within some error",
|
||||
format!(
|
||||
"({}).abs() {} error",
|
||||
lhs - rhs,
|
||||
if op == BinOpKind::Eq { '<' } else { '>' }
|
||||
),
|
||||
Applicability::HasPlaceholders, // snippet
|
||||
);
|
||||
if !(is_array(cx, left) || is_array(cx, right)) {
|
||||
db.span_suggestion(
|
||||
expr.span,
|
||||
"consider comparing them within some error",
|
||||
format!(
|
||||
"({}).abs() {} error",
|
||||
lhs - rhs,
|
||||
if op == BinOpKind::Eq { '<' } else { '>' }
|
||||
),
|
||||
Applicability::HasPlaceholders, // snippet
|
||||
);
|
||||
}
|
||||
db.span_note(expr.span, "`f32::EPSILON` and `f64::EPSILON` are available.");
|
||||
});
|
||||
} else if op == BinOpKind::Rem && is_integer_const(cx, right, 1) {
|
||||
|
@ -513,6 +515,10 @@ fn is_float(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
|
|||
matches!(value, ty::Float(_))
|
||||
}
|
||||
|
||||
fn is_array(cx: &LateContext<'_, '_>, expr: &Expr<'_>) -> bool {
|
||||
matches!(&walk_ptrs_ty(cx.tables.expr_ty(expr)).kind, ty::Array(_, _))
|
||||
}
|
||||
|
||||
fn check_to_owned(cx: &LateContext<'_, '_>, expr: &Expr<'_>, other: &Expr<'_>) {
|
||||
let (arg_ty, snip) = match expr.kind {
|
||||
ExprKind::MethodCall(.., ref args) if args.len() == 1 => {
|
||||
|
|
Loading…
Reference in a new issue