From cd9659ffcee35ade2148162a9b77f8d74656d43e Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 2 Feb 2021 12:25:13 +0100 Subject: Use the right `DefMap` when looking up modules --- crates/hir_def/src/nameres/collector.rs | 8 +++++++- crates/hir_def/src/nameres/path_resolution.rs | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'crates/hir_def/src/nameres') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index fcc8e2607..6e86cc4a7 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -592,7 +592,13 @@ impl DefCollector<'_> { // glob import from same crate => we do an initial // import, and then need to propagate any further // additions - let scope = &self.def_map[m.local_id].scope; + let def_map; + let scope = if m.block == self.def_map.block_id() { + &self.def_map[m.local_id].scope + } else { + def_map = m.def_map(self.db); + &def_map[m.local_id].scope + }; // Module scoped macros is included let items = scope diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index 2a0f8ec2b..2d1477160 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs @@ -271,8 +271,16 @@ impl DefMap { ); } + let def_map; + let module_data = if module.block == self.block_id() { + &self[module.local_id] + } else { + def_map = module.def_map(db); + &def_map[module.local_id] + }; + // Since it is a qualified path here, it should not contains legacy macros - self[module.local_id].scope.get(&segment) + module_data.scope.get(&segment) } ModuleDefId::AdtId(AdtId::EnumId(e)) => { // enum variant -- cgit v1.2.3