diff options
Diffstat (limited to 'crates/hir_def')
-rw-r--r-- | crates/hir_def/src/body/lower.rs | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 60b25db56..19f5065d1 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs | |||
@@ -177,12 +177,15 @@ impl ExprCollector<'_> { | |||
177 | } | 177 | } |
178 | 178 | ||
179 | fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { | 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 | let syntax_ptr = AstPtr::new(&expr); | 185 | let syntax_ptr = AstPtr::new(&expr); |
181 | if self.check_cfg(&expr).is_none() { | 186 | self.check_cfg(&expr)?; |
182 | return self.missing_expr(); | ||
183 | } | ||
184 | 187 | ||
185 | match expr { | 188 | Some(match expr { |
186 | ast::Expr::IfExpr(e) => { | 189 | ast::Expr::IfExpr(e) => { |
187 | let then_branch = self.collect_block_opt(e.then_branch()); | 190 | let then_branch = self.collect_block_opt(e.then_branch()); |
188 | 191 | ||
@@ -211,8 +214,9 @@ impl ExprCollector<'_> { | |||
211 | guard: None, | 214 | guard: None, |
212 | }, | 215 | }, |
213 | ]; | 216 | ]; |
214 | return self | 217 | return Some( |
215 | .alloc_expr(Expr::Match { expr: match_expr, arms }, syntax_ptr); | 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 | let match_expr = | 288 | let match_expr = |
285 | self.alloc_expr_desugared(Expr::Match { expr: match_expr, arms }); | 289 | self.alloc_expr_desugared(Expr::Match { expr: match_expr, arms }); |
286 | return self | 290 | return Some( |
287 | .alloc_expr(Expr::Loop { body: match_expr, label }, syntax_ptr); | 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 | ast::Expr::CallExpr(e) => { | 306 | ast::Expr::CallExpr(e) => { |
302 | let callee = self.collect_expr_opt(e.expr()); | 307 | let callee = self.collect_expr_opt(e.expr()); |
303 | let args = if let Some(arg_list) = e.arg_list() { | 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 | } else { | 310 | } else { |
306 | Vec::new() | 311 | Vec::new() |
307 | }; | 312 | }; |
@@ -310,7 +315,7 @@ impl ExprCollector<'_> { | |||
310 | ast::Expr::MethodCallExpr(e) => { | 315 | ast::Expr::MethodCallExpr(e) => { |
311 | let receiver = self.collect_expr_opt(e.receiver()); | 316 | let receiver = self.collect_expr_opt(e.receiver()); |
312 | let args = if let Some(arg_list) = e.arg_list() { | 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 | } else { | 319 | } else { |
315 | Vec::new() | 320 | Vec::new() |
316 | }; | 321 | }; |
@@ -538,7 +543,7 @@ impl ExprCollector<'_> { | |||
538 | self.alloc_expr(Expr::Missing, syntax_ptr) | 543 | self.alloc_expr(Expr::Missing, syntax_ptr) |
539 | } | 544 | } |
540 | } | 545 | } |
541 | } | 546 | }) |
542 | } | 547 | } |
543 | 548 | ||
544 | fn collect_macro_call<F: FnMut(&mut Self, Option<T>), T: ast::AstNode>( | 549 | fn collect_macro_call<F: FnMut(&mut Self, Option<T>), T: ast::AstNode>( |