From 75614b126b0fb7c0f1f7da4b4f37c32c56712fc7 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 9 Apr 2021 15:25:12 +0200 Subject: Resolve prelude and crate root names in the root DefMap --- crates/hir_def/src/nameres/path_resolution.rs | 38 ++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'crates/hir_def/src/nameres/path_resolution.rs') diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index a9cf651d2..ccc9f22eb 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs @@ -60,12 +60,26 @@ impl ResolvePathResult { } impl DefMap { - pub(super) fn resolve_name_in_extern_prelude(&self, name: &Name) -> PerNs { + pub(super) fn resolve_name_in_extern_prelude( + &self, + db: &dyn DefDatabase, + name: &Name, + ) -> PerNs { if name == &name!(self) { cov_mark::hit!(extern_crate_self_as); return PerNs::types(self.module_id(self.root).into(), Visibility::Public); } - self.extern_prelude + + let arc; + let root = match self.block { + Some(_) => { + arc = self.crate_root(db).def_map(db); + &*arc + } + None => self, + }; + + root.extern_prelude .get(name) .map_or(PerNs::none(), |&it| PerNs::types(it, Visibility::Public)) } @@ -191,7 +205,7 @@ impl DefMap { None => return ResolvePathResult::empty(ReachedFixedPoint::Yes), }; log::debug!("resolving {:?} in crate root (+ extern prelude)", segment); - self.resolve_name_in_crate_root_or_extern_prelude(&segment) + self.resolve_name_in_crate_root_or_extern_prelude(db, &segment) } PathKind::Plain => { let (_, segment) = match segments.next() { @@ -394,9 +408,21 @@ impl DefMap { from_legacy_macro.or(from_scope_or_builtin).or(from_extern_prelude).or(from_prelude) } - fn resolve_name_in_crate_root_or_extern_prelude(&self, name: &Name) -> PerNs { - let from_crate_root = self[self.root].scope.get(name); - let from_extern_prelude = self.resolve_name_in_extern_prelude(name); + fn resolve_name_in_crate_root_or_extern_prelude( + &self, + db: &dyn DefDatabase, + name: &Name, + ) -> PerNs { + let arc; + let crate_def_map = match self.block { + Some(_) => { + arc = self.crate_root(db).def_map(db); + &arc + } + None => self, + }; + let from_crate_root = crate_def_map[crate_def_map.root].scope.get(name); + let from_extern_prelude = self.resolve_name_in_extern_prelude(db, name); from_crate_root.or(from_extern_prelude) } -- cgit v1.2.3