Skip to content

Commit

Permalink
Fix bug in lint
Browse files Browse the repository at this point in the history
  • Loading branch information
JarredAllen committed Jul 17, 2020
1 parent 7c5d4a4 commit e85b590
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,10 @@ mod redundant_pattern_match {
}
}

let result_expr = match &op.kind {
ExprKind::AddrOf(_, _, borrowed) => borrowed,
_ => op,
};
span_lint_and_then(
cx,
REDUNDANT_PATTERN_MATCHING,
Expand All @@ -1524,7 +1528,7 @@ mod redundant_pattern_match {

// while let ... = ... { ... }
// ^^^
let op_span = op.span.source_callsite();
let op_span = result_expr.span.source_callsite();

// while let ... = ... { ... }
// ^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -1589,17 +1593,21 @@ mod redundant_pattern_match {
};

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(
cx,
REDUNDANT_PATTERN_MATCHING,
expr.span,
&format!("redundant pattern matching, consider using `{}`", good_method),
|diag| {
let span = expr.span.to(op.span);
diag.span_suggestion(
span,
"try this",
format!("{}.{}", snippet(cx, op.span, "_"), good_method),
format!("{}.{}", snippet(cx, result_expr.span, "_"), good_method),
Applicability::MaybeIncorrect, // snippet
);
},
Expand Down

0 comments on commit e85b590

Please sign in to comment.