diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-02 17:02:48 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-02 17:02:48 +0000 |
commit | 7e66cde76460d61cb19a19e4bb7bc1f6642e993d (patch) | |
tree | c8c20aff862d670f1baebd33d95e645a1281ca7f /crates/hir_def | |
parent | 12e8cc4aa29f616e43b4951e18b1f1f231e539a3 (diff) | |
parent | 5914f86d473f34e0fa78dc150024b07bd26a2db9 (diff) |
Merge #7525
7525: Fix resolution of `crate` paths from within blocks r=jonas-schievink a=jonas-schievink
They resolve to the crate root, not the DefMap's root module (which
can be a block)
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def')
-rw-r--r-- | crates/hir_def/src/nameres.rs | 5 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/path_resolution.rs | 4 |
2 files changed, 7 insertions, 2 deletions
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 5efc2fe47..0a15fc470 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs | |||
@@ -275,6 +275,11 @@ impl DefMap { | |||
275 | ModuleId { krate: self.krate, local_id, block } | 275 | ModuleId { krate: self.krate, local_id, block } |
276 | } | 276 | } |
277 | 277 | ||
278 | pub(crate) fn crate_root(&self) -> ModuleId { | ||
279 | let (root_map, _) = self.ancestor_maps(self.root).last().unwrap(); | ||
280 | root_map.module_id(root_map.root) | ||
281 | } | ||
282 | |||
278 | pub(crate) fn resolve_path( | 283 | pub(crate) fn resolve_path( |
279 | &self, | 284 | &self, |
280 | db: &dyn DefDatabase, | 285 | db: &dyn DefDatabase, |
diff --git a/crates/hir_def/src/nameres/path_resolution.rs b/crates/hir_def/src/nameres/path_resolution.rs index 2d1477160..ecf75c777 100644 --- a/crates/hir_def/src/nameres/path_resolution.rs +++ b/crates/hir_def/src/nameres/path_resolution.rs | |||
@@ -152,7 +152,7 @@ impl DefMap { | |||
152 | PathKind::DollarCrate(krate) => { | 152 | PathKind::DollarCrate(krate) => { |
153 | if krate == self.krate { | 153 | if krate == self.krate { |
154 | mark::hit!(macro_dollar_crate_self); | 154 | mark::hit!(macro_dollar_crate_self); |
155 | PerNs::types(self.module_id(self.root).into(), Visibility::Public) | 155 | PerNs::types(self.crate_root().into(), Visibility::Public) |
156 | } else { | 156 | } else { |
157 | let def_map = db.crate_def_map(krate); | 157 | let def_map = db.crate_def_map(krate); |
158 | let module = def_map.module_id(def_map.root); | 158 | let module = def_map.module_id(def_map.root); |
@@ -160,7 +160,7 @@ impl DefMap { | |||
160 | PerNs::types(module.into(), Visibility::Public) | 160 | PerNs::types(module.into(), Visibility::Public) |
161 | } | 161 | } |
162 | } | 162 | } |
163 | PathKind::Crate => PerNs::types(self.module_id(self.root).into(), Visibility::Public), | 163 | PathKind::Crate => PerNs::types(self.crate_root().into(), Visibility::Public), |
164 | // plain import or absolute path in 2015: crate-relative with | 164 | // plain import or absolute path in 2015: crate-relative with |
165 | // fallback to extern prelude (with the simplification in | 165 | // fallback to extern prelude (with the simplification in |
166 | // rust-lang/rust#57745) | 166 | // rust-lang/rust#57745) |