From f8f44cfb9b598efea7cfbabdad356912e9b09afd Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 21 Jan 2021 15:24:15 +0100 Subject: Fall back to parent DefMaps when resolving paths --- crates/hir_def/src/nameres/path_resolution.rs | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index 096a7d0ac..ec90f4e65 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs @@ -103,6 +103,43 @@ impl DefMap { original_module: LocalModuleId, path: &ModPath, shadow: BuiltinShadowMode, + ) -> ResolvePathResult { + let mut result = ResolvePathResult::empty(ReachedFixedPoint::No); + result.segment_index = Some(usize::max_value()); + + let mut current_map = self; + loop { + let new = current_map.resolve_path_fp_with_macro_single( + db, + mode, + original_module, + path, + shadow, + ); + + // Merge `new` into `result`. + result.resolved_def = result.resolved_def.or(new.resolved_def); + if result.reached_fixedpoint == ReachedFixedPoint::No { + result.reached_fixedpoint = new.reached_fixedpoint; + } + // FIXME: this doesn't seem right; what if the different namespace resolutions come from different crates? + result.krate = result.krate.or(new.krate); + result.segment_index = result.segment_index.min(new.segment_index); + + match ¤t_map.parent { + Some(map) => current_map = map, + None => return result, + } + } + } + + pub(super) fn resolve_path_fp_with_macro_single( + &self, + db: &dyn DefDatabase, + mode: ResolveMode, + original_module: LocalModuleId, + path: &ModPath, + shadow: BuiltinShadowMode, ) -> ResolvePathResult { let mut segments = path.segments.iter().enumerate(); let mut curr_per_ns: PerNs = match path.kind { -- cgit v1.2.3