Skip to content

Commit 2d509f8

Browse files
committed
Check if let guard in collapsible_match
1 parent 043cf97 commit 2d509f8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

clippy_lints/src/collapsible_match.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ fn check_arm(arm: &Arm<'_>, wild_outer_arm: &Arm<'_>, cx: &LateContext<'_>) {
8585
// the "wild-like" branches must be equal
8686
if SpanlessEq::new(cx).eq_expr(wild_inner_arm.body, wild_outer_arm.body);
8787
// the binding must not be used in the if guard
88-
if !matches!(arm.guard, Some(Guard::If(guard)) if LocalUsedVisitor::new(binding_id).check_expr(guard));
88+
if match arm.guard {
89+
None => true,
90+
Some(Guard::If(expr) | Guard::IfLet(_, expr)) => {
91+
!LocalUsedVisitor::new(binding_id).check_expr(expr)
92+
}
93+
};
8994
// ...or anywhere in the inner match
9095
if !arms_inner.iter().any(|arm| LocalUsedVisitor::new(binding_id).check_arm(arm));
9196
then {

0 commit comments

Comments
 (0)