From c89010df2d586eec33b50f3afcc4b2226da32672 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 14 Nov 2019 09:43:59 +0300 Subject: Add Expader::to_source --- crates/ra_hir_def/src/body.rs | 4 ++++ crates/ra_hir_def/src/body/lower.rs | 14 ++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 1c9c86449..622c836d1 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -34,6 +34,10 @@ impl Expander { self.original_file_id != self.current_file_id } + fn to_source(&self, ast: T) -> Source { + Source { file_id: self.current_file_id, ast } + } + fn resolve_path_as_macro(&self, db: &impl DefDatabase2, path: &Path) -> Option { self.crate_def_map.resolve_path(db, self.module.module_id, path).0.get_macros() } diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 602bcb220..1ea8ce249 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -4,7 +4,7 @@ use hir_expand::{ either::Either, hygiene::Hygiene, name::{self, AsName, Name}, - AstId, MacroCallLoc, MacroFileKind, Source, + AstId, MacroCallLoc, MacroFileKind, }; use ra_arena::Arena; use ra_syntax::{ @@ -99,9 +99,7 @@ where if !self.expander.is_in_expansion() { self.source_map.expr_map.insert(ptr, id); } - self.source_map - .expr_map_back - .insert(id, Source { file_id: self.expander.current_file_id, ast: ptr }); + self.source_map.expr_map_back.insert(id, self.expander.to_source(ptr)); id } // desugared exprs don't have ptr, that's wrong and should be fixed @@ -115,9 +113,7 @@ where if !self.expander.is_in_expansion() { self.source_map.expr_map.insert(ptr, id); } - self.source_map - .expr_map_back - .insert(id, Source { file_id: self.expander.current_file_id, ast: ptr }); + self.source_map.expr_map_back.insert(id, self.expander.to_source(ptr)); id } fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { @@ -125,9 +121,7 @@ where if !self.expander.is_in_expansion() { self.source_map.pat_map.insert(ptr, id); } - self.source_map - .pat_map_back - .insert(id, Source { file_id: self.expander.current_file_id, ast: ptr }); + self.source_map.pat_map_back.insert(id, self.expander.to_source(ptr)); id } -- cgit v1.2.3