diff options
author | Aleksey Kladov <[email protected]> | 2019-11-14 07:30:30 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-14 07:30:30 +0000 |
commit | da2ca01ebaaaaa47aa09c5848c53b145a68af8fa (patch) | |
tree | bed1d8bfef7cd3c42917d30fae2d8002dd00c38c /crates/ra_hir_def/src/body | |
parent | a73b7bb3f6af134c781cba1126350749c5a91144 (diff) |
Handle macro-generated expressions slightly less wrong
Diffstat (limited to 'crates/ra_hir_def/src/body')
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index c45500195..f6d79ddf0 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -94,10 +94,9 @@ where | |||
94 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { | 94 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { |
95 | let ptr = Either::A(ptr); | 95 | let ptr = Either::A(ptr); |
96 | let id = self.body.exprs.alloc(expr); | 96 | let id = self.body.exprs.alloc(expr); |
97 | if !self.expander.is_in_expansion() { | 97 | let src = self.expander.to_source(ptr); |
98 | self.source_map.expr_map.insert(ptr, id); | 98 | self.source_map.expr_map.insert(src, id); |
99 | } | 99 | self.source_map.expr_map_back.insert(id, src); |
100 | self.source_map.expr_map_back.insert(id, self.expander.to_source(ptr)); | ||
101 | id | 100 | id |
102 | } | 101 | } |
103 | // desugared exprs don't have ptr, that's wrong and should be fixed | 102 | // desugared exprs don't have ptr, that's wrong and should be fixed |
@@ -108,18 +107,16 @@ where | |||
108 | fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { | 107 | fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { |
109 | let ptr = Either::B(ptr); | 108 | let ptr = Either::B(ptr); |
110 | let id = self.body.exprs.alloc(expr); | 109 | let id = self.body.exprs.alloc(expr); |
111 | if !self.expander.is_in_expansion() { | 110 | let src = self.expander.to_source(ptr); |
112 | self.source_map.expr_map.insert(ptr, id); | 111 | self.source_map.expr_map.insert(src, id); |
113 | } | 112 | self.source_map.expr_map_back.insert(id, src); |
114 | self.source_map.expr_map_back.insert(id, self.expander.to_source(ptr)); | ||
115 | id | 113 | id |
116 | } | 114 | } |
117 | fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { | 115 | fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { |
118 | let id = self.body.pats.alloc(pat); | 116 | let id = self.body.pats.alloc(pat); |
119 | if !self.expander.is_in_expansion() { | 117 | let src = self.expander.to_source(ptr); |
120 | self.source_map.pat_map.insert(ptr, id); | 118 | self.source_map.pat_map.insert(src, id); |
121 | } | 119 | self.source_map.pat_map_back.insert(id, src); |
122 | self.source_map.pat_map_back.insert(id, self.expander.to_source(ptr)); | ||
123 | id | 120 | id |
124 | } | 121 | } |
125 | 122 | ||
@@ -277,7 +274,8 @@ where | |||
277 | ast::Expr::ParenExpr(e) => { | 274 | ast::Expr::ParenExpr(e) => { |
278 | let inner = self.collect_expr_opt(e.expr()); | 275 | let inner = self.collect_expr_opt(e.expr()); |
279 | // make the paren expr point to the inner expression as well | 276 | // make the paren expr point to the inner expression as well |
280 | self.source_map.expr_map.insert(Either::A(syntax_ptr), inner); | 277 | let src = self.expander.to_source(Either::A(syntax_ptr)); |
278 | self.source_map.expr_map.insert(src, inner); | ||
281 | inner | 279 | inner |
282 | } | 280 | } |
283 | ast::Expr::ReturnExpr(e) => { | 281 | ast::Expr::ReturnExpr(e) => { |