Skip to content

Commit e85b590

Browse files
committed
Fix bug in lint
1 parent 7c5d4a4 commit e85b590

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

clippy_lints/src/matches.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,10 @@ mod redundant_pattern_match {
15121512
}
15131513
}
15141514

1515+
let result_expr = match &op.kind {
1516+
ExprKind::AddrOf(_, _, borrowed) => borrowed,
1517+
_ => op,
1518+
};
15151519
span_lint_and_then(
15161520
cx,
15171521
REDUNDANT_PATTERN_MATCHING,
@@ -1524,7 +1528,7 @@ mod redundant_pattern_match {
15241528

15251529
// while let ... = ... { ... }
15261530
// ^^^
1527-
let op_span = op.span.source_callsite();
1531+
let op_span = result_expr.span.source_callsite();
15281532

15291533
// while let ... = ... { ... }
15301534
// ^^^^^^^^^^^^^^^^^^^
@@ -1589,17 +1593,21 @@ mod redundant_pattern_match {
15891593
};
15901594

15911595
if let Some(good_method) = found_good_method {
1596+
let span = expr.span.to(op.span);
1597+
let result_expr = match &op.kind {
1598+
ExprKind::AddrOf(_, _, borrowed) => borrowed,
1599+
_ => op,
1600+
};
15921601
span_lint_and_then(
15931602
cx,
15941603
REDUNDANT_PATTERN_MATCHING,
15951604
expr.span,
15961605
&format!("redundant pattern matching, consider using `{}`", good_method),
15971606
|diag| {
1598-
let span = expr.span.to(op.span);
15991607
diag.span_suggestion(
16001608
span,
16011609
"try this",
1602-
format!("{}.{}", snippet(cx, op.span, "_"), good_method),
1610+
format!("{}.{}", snippet(cx, result_expr.span, "_"), good_method),
16031611
Applicability::MaybeIncorrect, // snippet
16041612
);
16051613
},

0 commit comments

Comments
 (0)