Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1021327

Browse files
committed
Simplify if_chain
1 parent 4bbd7e4 commit 1021327

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

clippy_lints/src/collapsible_if.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,10 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
144144
if !block_starts_with_comment(cx, then);
145145
if let Some(inner) = expr_block(then);
146146
if let ast::ExprKind::If(ref check_inner, ref content, None) = inner.kind;
147+
// Prevent triggering on `if c { if let a = b { .. } }`.
148+
if !matches!(check_inner.kind, ast::ExprKind::Let(..));
149+
if expr.span.ctxt() == inner.span.ctxt();
147150
then {
148-
if let ast::ExprKind::Let(..) = check_inner.kind {
149-
// Prevent triggering on `if c { if let a = b { .. } }`.
150-
return;
151-
}
152-
153-
if expr.span.ctxt() != inner.span.ctxt() {
154-
return;
155-
}
156151
span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this `if` statement can be collapsed", |diag| {
157152
let lhs = Sugg::ast(cx, check, "..");
158153
let rhs = Sugg::ast(cx, check_inner, "..");

0 commit comments

Comments
 (0)