@@ -93,20 +93,14 @@ declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF, COLLAPSIBLE_ELSE_IF]);
93
93
94
94
impl EarlyLintPass for CollapsibleIf {
95
95
fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , expr : & ast:: Expr ) {
96
- if !expr. span . from_expansion ( ) {
97
- check_if ( cx, expr) ;
98
- }
99
- }
100
- }
101
-
102
- fn check_if ( cx : & EarlyContext < ' _ > , expr : & ast:: Expr ) {
103
- if let ast:: ExprKind :: If ( check, then, else_) = & expr. kind {
104
- if let Some ( else_) = else_ {
105
- check_collapsible_maybe_if_let ( cx, then. span , else_) ;
106
- } else if let ast:: ExprKind :: Let ( ..) = check. kind {
107
- // Prevent triggering on `if let a = b { if c { .. } }`.
108
- } else {
109
- check_collapsible_no_if_let ( cx, expr, check, then) ;
96
+ if let ast:: ExprKind :: If ( cond, then, else_) = & expr. kind
97
+ && !expr. span . from_expansion ( )
98
+ {
99
+ if let Some ( else_) = else_ {
100
+ check_collapsible_maybe_if_let ( cx, then. span , else_) ;
101
+ } else if !matches ! ( cond. kind, ast:: ExprKind :: Let ( ..) ) {
102
+ check_collapsible_no_if_let ( cx, expr, cond, then) ;
103
+ }
110
104
}
111
105
}
112
106
}
@@ -189,13 +183,10 @@ fn check_collapsible_no_if_let(cx: &EarlyContext<'_>, expr: &ast::Expr, check: &
189
183
190
184
/// If the block contains only one expression, return it.
191
185
fn expr_block ( block : & ast:: Block ) -> Option < & ast:: Expr > {
192
- let mut it = block. stmts . iter ( ) ;
193
-
194
- if let ( Some ( stmt) , None ) = ( it. next ( ) , it. next ( ) ) {
195
- match stmt. kind {
196
- ast:: StmtKind :: Expr ( ref expr) | ast:: StmtKind :: Semi ( ref expr) => Some ( expr) ,
197
- _ => None ,
198
- }
186
+ if let [ stmt] = & * block. stmts
187
+ && let ast:: StmtKind :: Expr ( expr) | ast:: StmtKind :: Semi ( expr) = & stmt. kind
188
+ {
189
+ Some ( expr)
199
190
} else {
200
191
None
201
192
}
0 commit comments