@@ -177,12 +177,15 @@ impl ExprCollector<'_> {
177
177
}
178
178
179
179
fn collect_expr ( & mut self , expr : ast:: Expr ) -> ExprId {
180
+ self . maybe_collect_expr ( expr) . unwrap_or_else ( || self . missing_expr ( ) )
181
+ }
182
+
183
+ /// Returns `None` if the expression is `#[cfg]`d out.
184
+ fn maybe_collect_expr ( & mut self , expr : ast:: Expr ) -> Option < ExprId > {
180
185
let syntax_ptr = AstPtr :: new ( & expr) ;
181
- if self . check_cfg ( & expr) . is_none ( ) {
182
- return self . missing_expr ( ) ;
183
- }
186
+ self . check_cfg ( & expr) ?;
184
187
185
- match expr {
188
+ Some ( match expr {
186
189
ast:: Expr :: IfExpr ( e) => {
187
190
let then_branch = self . collect_block_opt ( e. then_branch ( ) ) ;
188
191
@@ -211,8 +214,9 @@ impl ExprCollector<'_> {
211
214
guard: None ,
212
215
} ,
213
216
] ;
214
- return self
215
- . alloc_expr ( Expr :: Match { expr : match_expr, arms } , syntax_ptr) ;
217
+ return Some (
218
+ self . alloc_expr ( Expr :: Match { expr : match_expr, arms } , syntax_ptr) ,
219
+ ) ;
216
220
}
217
221
} ,
218
222
} ;
@@ -283,8 +287,9 @@ impl ExprCollector<'_> {
283
287
] ;
284
288
let match_expr =
285
289
self . alloc_expr_desugared ( Expr :: Match { expr : match_expr, arms } ) ;
286
- return self
287
- . alloc_expr ( Expr :: Loop { body : match_expr, label } , syntax_ptr) ;
290
+ return Some (
291
+ self . alloc_expr ( Expr :: Loop { body : match_expr, label } , syntax_ptr) ,
292
+ ) ;
288
293
}
289
294
} ,
290
295
} ;
@@ -301,7 +306,7 @@ impl ExprCollector<'_> {
301
306
ast:: Expr :: CallExpr ( e) => {
302
307
let callee = self . collect_expr_opt ( e. expr ( ) ) ;
303
308
let args = if let Some ( arg_list) = e. arg_list ( ) {
304
- arg_list. args ( ) . map ( |e| self . collect_expr ( e) ) . collect ( )
309
+ arg_list. args ( ) . filter_map ( |e| self . maybe_collect_expr ( e) ) . collect ( )
305
310
} else {
306
311
Vec :: new ( )
307
312
} ;
@@ -310,7 +315,7 @@ impl ExprCollector<'_> {
310
315
ast:: Expr :: MethodCallExpr ( e) => {
311
316
let receiver = self . collect_expr_opt ( e. receiver ( ) ) ;
312
317
let args = if let Some ( arg_list) = e. arg_list ( ) {
313
- arg_list. args ( ) . map ( |e| self . collect_expr ( e) ) . collect ( )
318
+ arg_list. args ( ) . filter_map ( |e| self . maybe_collect_expr ( e) ) . collect ( )
314
319
} else {
315
320
Vec :: new ( )
316
321
} ;
@@ -538,7 +543,7 @@ impl ExprCollector<'_> {
538
543
self . alloc_expr ( Expr :: Missing , syntax_ptr)
539
544
}
540
545
}
541
- }
546
+ } )
542
547
}
543
548
544
549
fn collect_macro_call < F : FnMut ( & mut Self , Option < T > ) , T : ast:: AstNode > (
0 commit comments