@@ -122,6 +122,7 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
122122 if let ast:: ExprKind :: Block ( ref block, _) = else_. kind;
123123 if !block_starts_with_comment( cx, block) ;
124124 if let Some ( else_) = expr_block( block) ;
125+ if else_. attrs. is_empty( ) ;
125126 if !else_. span. from_expansion( ) ;
126127 if let ast:: ExprKind :: If ( ..) = else_. kind;
127128 then {
@@ -143,16 +144,12 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
143144 if_chain ! {
144145 if !block_starts_with_comment( cx, then) ;
145146 if let Some ( inner) = expr_block( then) ;
147+ if inner. attrs. is_empty( ) ;
146148 if let ast:: ExprKind :: If ( ref check_inner, ref content, None ) = inner. kind;
149+ // Prevent triggering on `if c { if let a = b { .. } }`.
150+ if !matches!( check_inner. kind, ast:: ExprKind :: Let ( ..) ) ;
151+ if expr. span. ctxt( ) == inner. span. ctxt( ) ;
147152 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- }
156153 span_lint_and_then( cx, COLLAPSIBLE_IF , expr. span, "this `if` statement can be collapsed" , |diag| {
157154 let lhs = Sugg :: ast( cx, check, ".." ) ;
158155 let rhs = Sugg :: ast( cx, check_inner, ".." ) ;
0 commit comments