diff options
Diffstat (limited to 'crates/ra_hir/src/expr.rs')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 5cf0f5e3f..6866fc2ac 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | use std::ops::Index; | ||
1 | use std::sync::Arc; | 2 | use std::sync::Arc; |
2 | 3 | ||
3 | use rustc_hash::FxHashMap; | 4 | use rustc_hash::FxHashMap; |
@@ -44,14 +45,6 @@ pub struct BodySyntaxMapping { | |||
44 | } | 45 | } |
45 | 46 | ||
46 | impl Body { | 47 | impl Body { |
47 | pub fn expr(&self, expr: ExprId) -> &Expr { | ||
48 | &self.exprs[expr] | ||
49 | } | ||
50 | |||
51 | pub fn pat(&self, pat: PatId) -> &Pat { | ||
52 | &self.pats[pat] | ||
53 | } | ||
54 | |||
55 | pub fn args(&self) -> &[PatId] { | 48 | pub fn args(&self) -> &[PatId] { |
56 | &self.args | 49 | &self.args |
57 | } | 50 | } |
@@ -61,6 +54,22 @@ impl Body { | |||
61 | } | 54 | } |
62 | } | 55 | } |
63 | 56 | ||
57 | impl Index<ExprId> for Body { | ||
58 | type Output = Expr; | ||
59 | |||
60 | fn index(&self, expr: ExprId) -> &Expr { | ||
61 | &self.exprs[expr] | ||
62 | } | ||
63 | } | ||
64 | |||
65 | impl Index<PatId> for Body { | ||
66 | type Output = Pat; | ||
67 | |||
68 | fn index(&self, pat: PatId) -> &Pat { | ||
69 | &self.pats[pat] | ||
70 | } | ||
71 | } | ||
72 | |||
64 | impl BodySyntaxMapping { | 73 | impl BodySyntaxMapping { |
65 | pub fn expr_syntax(&self, expr: ExprId) -> Option<LocalSyntaxPtr> { | 74 | pub fn expr_syntax(&self, expr: ExprId) -> Option<LocalSyntaxPtr> { |
66 | self.expr_syntax_mapping_back.get(&expr).cloned() | 75 | self.expr_syntax_mapping_back.get(&expr).cloned() |
@@ -377,11 +386,7 @@ impl ExprCollector { | |||
377 | syntax_ptr, | 386 | syntax_ptr, |
378 | ) | 387 | ) |
379 | } else { | 388 | } else { |
380 | let condition = if let Some(condition) = e.condition() { | 389 | let condition = self.collect_expr_opt(e.condition().and_then(|c| c.expr())); |
381 | self.collect_expr_opt(condition.expr()) | ||
382 | } else { | ||
383 | self.exprs.alloc(Expr::Missing) | ||
384 | }; | ||
385 | let then_branch = self.collect_block_opt(e.then_branch()); | 390 | let then_branch = self.collect_block_opt(e.then_branch()); |
386 | let else_branch = e.else_branch().map(|e| self.collect_block(e)); | 391 | let else_branch = e.else_branch().map(|e| self.collect_block(e)); |
387 | self.alloc_expr( | 392 | self.alloc_expr( |