From 9c3b25177e3c8d609dd24d2c2e01cbb82cab665f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 3 Sep 2019 11:04:38 +0300 Subject: Correctly build BodySourceMap for macro-expanded expressions --- crates/ra_hir/src/expr/lower.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'crates/ra_hir/src/expr/lower.rs') diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs index 7b3e55b7e..6afd80989 100644 --- a/crates/ra_hir/src/expr/lower.rs +++ b/crates/ra_hir/src/expr/lower.rs @@ -14,7 +14,7 @@ use crate::{ ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, type_ref::TypeRef, DefWithBody, Either, HirDatabase, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path, - Resolver, + Resolver, Source, }; use super::{ @@ -103,11 +103,13 @@ where let id = self.body.exprs.alloc(expr); if self.current_file_id == self.original_file_id { self.source_map.expr_map.insert(ptr, id); - self.source_map.expr_map_back.insert(id, ptr); } + self.source_map + .expr_map_back + .insert(id, Source { file_id: self.current_file_id, ast: ptr }); id } - // deshugared exprs don't have ptr, that's wrong and should be fixed + // desugared exprs don't have ptr, that's wrong and should be fixed // somehow. fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId { self.body.exprs.alloc(expr) @@ -117,18 +119,18 @@ where let id = self.body.exprs.alloc(expr); if self.current_file_id == self.original_file_id { self.source_map.expr_map.insert(ptr, id); - self.source_map.expr_map_back.insert(id, ptr); } + self.source_map + .expr_map_back + .insert(id, Source { file_id: self.current_file_id, ast: ptr }); id } fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { let id = self.body.pats.alloc(pat); - if self.current_file_id == self.original_file_id { self.source_map.pat_map.insert(ptr, id); - self.source_map.pat_map_back.insert(id, ptr); } - + self.source_map.pat_map_back.insert(id, Source { file_id: self.current_file_id, ast: ptr }); id } -- cgit v1.2.3