aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r--crates/hir_def/src/body.rs11
-rw-r--r--crates/hir_def/src/body/lower.rs14
2 files changed, 11 insertions, 14 deletions
diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs
index 41abd8f83..9a432f7d1 100644
--- a/crates/hir_def/src/body.rs
+++ b/crates/hir_def/src/body.rs
@@ -33,7 +33,7 @@ use crate::{
33 nameres::DefMap, 33 nameres::DefMap,
34 path::{ModPath, Path}, 34 path::{ModPath, Path},
35 src::HasSource, 35 src::HasSource,
36 AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId, 36 AsMacroCall, DefWithBodyId, HasModule, LocalModuleId, Lookup, ModuleId,
37}; 37};
38 38
39/// A subset of Expander that only deals with cfg attributes. We only need it to 39/// A subset of Expander that only deals with cfg attributes. We only need it to
@@ -49,7 +49,7 @@ pub(crate) struct Expander {
49 def_map: Arc<DefMap>, 49 def_map: Arc<DefMap>,
50 current_file_id: HirFileId, 50 current_file_id: HirFileId,
51 ast_id_map: Arc<AstIdMap>, 51 ast_id_map: Arc<AstIdMap>,
52 module: ModuleId, 52 module: LocalModuleId,
53 recursion_limit: usize, 53 recursion_limit: usize,
54} 54}
55 55
@@ -94,7 +94,7 @@ impl Expander {
94 def_map: crate_def_map, 94 def_map: crate_def_map,
95 current_file_id, 95 current_file_id,
96 ast_id_map, 96 ast_id_map,
97 module, 97 module: module.local_id,
98 recursion_limit: 0, 98 recursion_limit: 0,
99 } 99 }
100 } 100 }
@@ -197,10 +197,7 @@ impl Expander {
197 } 197 }
198 198
199 fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> { 199 fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> {
200 self.def_map 200 self.def_map.resolve_path(db, self.module, path, BuiltinShadowMode::Other).0.take_macros()
201 .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other)
202 .0
203 .take_macros()
204 } 201 }
205 202
206 fn ast_id<N: AstNode>(&self, item: &N) -> AstId<N> { 203 fn ast_id<N: AstNode>(&self, item: &N) -> AstId<N> {
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs
index 540c6c9ad..28b11cdde 100644
--- a/crates/hir_def/src/body/lower.rs
+++ b/crates/hir_def/src/body/lower.rs
@@ -698,15 +698,15 @@ impl ExprCollector<'_> {
698 698
699 fn collect_block(&mut self, block: ast::BlockExpr) -> ExprId { 699 fn collect_block(&mut self, block: ast::BlockExpr) -> ExprId {
700 let ast_id = self.expander.ast_id(&block); 700 let ast_id = self.expander.ast_id(&block);
701 let block_loc = BlockLoc { ast_id, module: self.expander.module }; 701 let block_loc =
702 BlockLoc { ast_id, module: self.expander.def_map.module_id(self.expander.module) };
702 let block_id = self.db.intern_block(block_loc); 703 let block_id = self.db.intern_block(block_loc);
703 let opt_def_map = self.db.block_def_map(block_id); 704 let opt_def_map = self.db.block_def_map(block_id);
704 let has_def_map = opt_def_map.is_some(); 705 let has_def_map = opt_def_map.is_some();
705 let def_map = opt_def_map.unwrap_or_else(|| self.expander.def_map.clone()); 706 let def_map = opt_def_map.unwrap_or_else(|| self.expander.def_map.clone());
706 let module = 707 let module = if has_def_map { def_map.root() } else { self.expander.module };
707 if has_def_map { def_map.module_id(def_map.root()) } else { self.expander.module };
708 let prev_def_map = mem::replace(&mut self.expander.def_map, def_map); 708 let prev_def_map = mem::replace(&mut self.expander.def_map, def_map);
709 let prev_module = mem::replace(&mut self.expander.module, module); 709 let prev_local_module = mem::replace(&mut self.expander.module, module);
710 710
711 self.collect_stmts_items(block.statements()); 711 self.collect_stmts_items(block.statements());
712 let statements = 712 let statements =
@@ -719,7 +719,7 @@ impl ExprCollector<'_> {
719 ); 719 );
720 720
721 self.expander.def_map = prev_def_map; 721 self.expander.def_map = prev_def_map;
722 self.expander.module = prev_module; 722 self.expander.module = prev_local_module;
723 expr_id 723 expr_id
724 } 724 }
725 725
@@ -812,7 +812,7 @@ impl ExprCollector<'_> {
812 } 812 }
813 Either::Right(e) => { 813 Either::Right(e) => {
814 let mac = MacroDefId { 814 let mac = MacroDefId {
815 krate: self.expander.module.krate, 815 krate: self.expander.def_map.krate(),
816 ast_id: Some(self.expander.ast_id(&e)), 816 ast_id: Some(self.expander.ast_id(&e)),
817 kind: MacroDefKind::Declarative, 817 kind: MacroDefKind::Declarative,
818 local_inner: false, 818 local_inner: false,
@@ -852,7 +852,7 @@ impl ExprCollector<'_> {
852 // decide that, we need to try resolving the name. 852 // decide that, we need to try resolving the name.
853 let (resolved, _) = self.expander.def_map.resolve_path( 853 let (resolved, _) = self.expander.def_map.resolve_path(
854 self.db, 854 self.db,
855 self.expander.module.local_id, 855 self.expander.module,
856 &name.clone().into(), 856 &name.clone().into(),
857 BuiltinShadowMode::Other, 857 BuiltinShadowMode::Other,
858 ); 858 );