@@ -122,6 +122,7 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
122
122
if let ast:: ExprKind :: Block ( ref block, _) = else_. kind;
123
123
if !block_starts_with_comment( cx, block) ;
124
124
if let Some ( else_) = expr_block( block) ;
125
+ if else_. attrs. is_empty( ) ;
125
126
if !else_. span. from_expansion( ) ;
126
127
if let ast:: ExprKind :: If ( ..) = else_. kind;
127
128
then {
@@ -143,16 +144,12 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
143
144
if_chain ! {
144
145
if !block_starts_with_comment( cx, then) ;
145
146
if let Some ( inner) = expr_block( then) ;
147
+ if inner. attrs. is_empty( ) ;
146
148
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( ) ;
147
152
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
- }
156
153
span_lint_and_then( cx, COLLAPSIBLE_IF , expr. span, "this `if` statement can be collapsed" , |diag| {
157
154
let lhs = Sugg :: ast( cx, check, ".." ) ;
158
155
let rhs = Sugg :: ast( cx, check_inner, ".." ) ;
0 commit comments