Fix bug in lint

This commit is contained in:
JarredAllen 2020-07-17 10:40:01 -07:00
parent 7c5d4a4145
commit e85b590936

View File

@ -1512,6 +1512,10 @@ fn find_suggestion(cx: &LateContext<'_>, hir_id: HirId, path: &QPath<'_>) -> Opt
} }
} }
let result_expr = match &op.kind {
ExprKind::AddrOf(_, _, borrowed) => borrowed,
_ => op,
};
span_lint_and_then( span_lint_and_then(
cx, cx,
REDUNDANT_PATTERN_MATCHING, REDUNDANT_PATTERN_MATCHING,
@ -1524,7 +1528,7 @@ fn find_suggestion(cx: &LateContext<'_>, hir_id: HirId, path: &QPath<'_>) -> Opt
// while let ... = ... { ... } // while let ... = ... { ... }
// ^^^ // ^^^
let op_span = op.span.source_callsite(); let op_span = result_expr.span.source_callsite();
// while let ... = ... { ... } // while let ... = ... { ... }
// ^^^^^^^^^^^^^^^^^^^ // ^^^^^^^^^^^^^^^^^^^
@ -1589,17 +1593,21 @@ fn find_sugg_for_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op: &
}; };
if let Some(good_method) = found_good_method { if let Some(good_method) = found_good_method {
let span = expr.span.to(op.span);
let result_expr = match &op.kind {
ExprKind::AddrOf(_, _, borrowed) => borrowed,
_ => op,
};
span_lint_and_then( span_lint_and_then(
cx, cx,
REDUNDANT_PATTERN_MATCHING, REDUNDANT_PATTERN_MATCHING,
expr.span, expr.span,
&format!("redundant pattern matching, consider using `{}`", good_method), &format!("redundant pattern matching, consider using `{}`", good_method),
|diag| { |diag| {
let span = expr.span.to(op.span);
diag.span_suggestion( diag.span_suggestion(
span, span,
"try this", "try this",
format!("{}.{}", snippet(cx, op.span, "_"), good_method), format!("{}.{}", snippet(cx, result_expr.span, "_"), good_method),
Applicability::MaybeIncorrect, // snippet Applicability::MaybeIncorrect, // snippet
); );
}, },