diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-02 11:37:45 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-02 11:37:45 +0000 |
commit | 8720f7f14688257d320de44e1354c62fce1a6bcf (patch) | |
tree | d5cbb565fbcdb5378ab4dbc4cf885933eb39eedd | |
parent | 157156276b32c4edca337e6389dc70a203c7c681 (diff) | |
parent | cd9659ffcee35ade2148162a9b77f8d74656d43e (diff) |
Merge #7518
7518: Use the right `DefMap` when looking up modules r=jonas-schievink a=jonas-schievink
Fixes the bugs encountered in https://github.com/rust-analyzer/rust-analyzer/pull/7506#issuecomment-771417467
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
-rw-r--r-- | crates/hir_def/src/nameres.rs | 4 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 8 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/path_resolution.rs | 10 |
3 files changed, 20 insertions, 2 deletions
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs index 6169b3bbc..5efc2fe47 100644 --- a/crates/hir_def/src/nameres.rs +++ b/crates/hir_def/src/nameres.rs | |||
@@ -258,6 +258,10 @@ impl DefMap { | |||
258 | self.krate | 258 | self.krate |
259 | } | 259 | } |
260 | 260 | ||
261 | pub(crate) fn block_id(&self) -> Option<BlockId> { | ||
262 | self.block.as_ref().map(|block| block.block) | ||
263 | } | ||
264 | |||
261 | pub(crate) fn prelude(&self) -> Option<ModuleId> { | 265 | pub(crate) fn prelude(&self) -> Option<ModuleId> { |
262 | self.prelude | 266 | self.prelude |
263 | } | 267 | } |
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<'_> { | |||
592 | // glob import from same crate => we do an initial | 592 | // glob import from same crate => we do an initial |
593 | // import, and then need to propagate any further | 593 | // import, and then need to propagate any further |
594 | // additions | 594 | // additions |
595 | let scope = &self.def_map[m.local_id].scope; | 595 | let def_map; |
596 | let scope = if m.block == self.def_map.block_id() { | ||
597 | &self.def_map[m.local_id].scope | ||
598 | } else { | ||
599 | def_map = m.def_map(self.db); | ||
600 | &def_map[m.local_id].scope | ||
601 | }; | ||
596 | 602 | ||
597 | // Module scoped macros is included | 603 | // Module scoped macros is included |
598 | let items = scope | 604 | 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 { | |||
271 | ); | 271 | ); |
272 | } | 272 | } |
273 | 273 | ||
274 | let def_map; | ||
275 | let module_data = if module.block == self.block_id() { | ||
276 | &self[module.local_id] | ||
277 | } else { | ||
278 | def_map = module.def_map(db); | ||
279 | &def_map[module.local_id] | ||
280 | }; | ||
281 | |||
274 | // Since it is a qualified path here, it should not contains legacy macros | 282 | // Since it is a qualified path here, it should not contains legacy macros |
275 | self[module.local_id].scope.get(&segment) | 283 | module_data.scope.get(&segment) |
276 | } | 284 | } |
277 | ModuleDefId::AdtId(AdtId::EnumId(e)) => { | 285 | ModuleDefId::AdtId(AdtId::EnumId(e)) => { |
278 | // enum variant | 286 | // enum variant |