diff options
Diffstat (limited to 'crates/ra_hir_def/src/body')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index c18e6879b..ec1b0c2e7 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -14,9 +14,10 @@ use ra_syntax::{ | |||
14 | }; | 14 | }; |
15 | use test_utils::tested_by; | 15 | use test_utils::tested_by; |
16 | 16 | ||
17 | use super::{ExprSource, PatSource}; | ||
17 | use crate::{ | 18 | use crate::{ |
18 | adt::StructKind, | 19 | adt::StructKind, |
19 | body::{Body, BodySourceMap, Expander, PatPtr}, | 20 | body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax}, |
20 | builtin_type::{BuiltinFloat, BuiltinInt}, | 21 | builtin_type::{BuiltinFloat, BuiltinInt}, |
21 | db::DefDatabase, | 22 | db::DefDatabase, |
22 | expr::{ | 23 | expr::{ |
@@ -102,44 +103,48 @@ where | |||
102 | 103 | ||
103 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { | 104 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { |
104 | let ptr = Either::Left(ptr); | 105 | let ptr = Either::Left(ptr); |
105 | let id = self.body.exprs.alloc(expr); | ||
106 | let src = self.expander.to_source(ptr); | 106 | let src = self.expander.to_source(ptr); |
107 | let id = self.make_expr(expr, Ok(src)); | ||
107 | self.source_map.expr_map.insert(src, id); | 108 | self.source_map.expr_map.insert(src, id); |
108 | self.source_map.expr_map_back.insert(id, src); | ||
109 | id | 109 | id |
110 | } | 110 | } |
111 | // desugared exprs don't have ptr, that's wrong and should be fixed | 111 | // desugared exprs don't have ptr, that's wrong and should be fixed |
112 | // somehow. | 112 | // somehow. |
113 | fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId { | 113 | fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId { |
114 | self.body.exprs.alloc(expr) | 114 | self.make_expr(expr, Err(SyntheticSyntax)) |
115 | } | 115 | } |
116 | fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { | 116 | fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { |
117 | let ptr = Either::Right(ptr); | 117 | let ptr = Either::Right(ptr); |
118 | let id = self.body.exprs.alloc(expr); | ||
119 | let src = self.expander.to_source(ptr); | 118 | let src = self.expander.to_source(ptr); |
119 | let id = self.make_expr(expr, Ok(src)); | ||
120 | self.source_map.expr_map.insert(src, id); | 120 | self.source_map.expr_map.insert(src, id); |
121 | id | ||
122 | } | ||
123 | fn empty_block(&mut self) -> ExprId { | ||
124 | self.alloc_expr_desugared(Expr::Block { statements: Vec::new(), tail: None }) | ||
125 | } | ||
126 | fn missing_expr(&mut self) -> ExprId { | ||
127 | self.alloc_expr_desugared(Expr::Missing) | ||
128 | } | ||
129 | fn make_expr(&mut self, expr: Expr, src: Result<ExprSource, SyntheticSyntax>) -> ExprId { | ||
130 | let id = self.body.exprs.alloc(expr); | ||
121 | self.source_map.expr_map_back.insert(id, src); | 131 | self.source_map.expr_map_back.insert(id, src); |
122 | id | 132 | id |
123 | } | 133 | } |
134 | |||
124 | fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { | 135 | fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { |
125 | let id = self.body.pats.alloc(pat); | ||
126 | let src = self.expander.to_source(ptr); | 136 | let src = self.expander.to_source(ptr); |
137 | let id = self.make_pat(pat, Ok(src)); | ||
127 | self.source_map.pat_map.insert(src, id); | 138 | self.source_map.pat_map.insert(src, id); |
128 | self.source_map.pat_map_back.insert(id, src); | ||
129 | id | 139 | id |
130 | } | 140 | } |
131 | |||
132 | fn empty_block(&mut self) -> ExprId { | ||
133 | let block = Expr::Block { statements: Vec::new(), tail: None }; | ||
134 | self.body.exprs.alloc(block) | ||
135 | } | ||
136 | |||
137 | fn missing_expr(&mut self) -> ExprId { | ||
138 | self.body.exprs.alloc(Expr::Missing) | ||
139 | } | ||
140 | |||
141 | fn missing_pat(&mut self) -> PatId { | 141 | fn missing_pat(&mut self) -> PatId { |
142 | self.body.pats.alloc(Pat::Missing) | 142 | self.make_pat(Pat::Missing, Err(SyntheticSyntax)) |
143 | } | ||
144 | fn make_pat(&mut self, pat: Pat, src: Result<PatSource, SyntheticSyntax>) -> PatId { | ||
145 | let id = self.body.pats.alloc(pat); | ||
146 | self.source_map.pat_map_back.insert(id, src); | ||
147 | id | ||
143 | } | 148 | } |
144 | 149 | ||
145 | fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { | 150 | fn collect_expr(&mut self, expr: ast::Expr) -> ExprId { |