From 10213277815cdf4d32ccadf17ae47aa03b5399cd Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 8 Feb 2021 10:51:40 -0600 Subject: [PATCH] Simplify if_chain --- clippy_lints/src/collapsible_if.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index 93ccc76d0c9..9edd85c8d17 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -144,15 +144,10 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: & if !block_starts_with_comment(cx, then); if let Some(inner) = expr_block(then); if let ast::ExprKind::If(ref check_inner, ref content, None) = inner.kind; + // Prevent triggering on `if c { if let a = b { .. } }`. + if !matches!(check_inner.kind, ast::ExprKind::Let(..)); + if expr.span.ctxt() == inner.span.ctxt(); then { - if let ast::ExprKind::Let(..) = check_inner.kind { - // Prevent triggering on `if c { if let a = b { .. } }`. - return; - } - - if expr.span.ctxt() != inner.span.ctxt() { - return; - } span_lint_and_then(cx, COLLAPSIBLE_IF, expr.span, "this `if` statement can be collapsed", |diag| { let lhs = Sugg::ast(cx, check, ".."); let rhs = Sugg::ast(cx, check_inner, "..");