diff options
| author | Chayim Refael Friedman <chayimfr@gmail.com> | 2024-12-04 03:15:32 +0200 |
|---|---|---|
| committer | Chayim Refael Friedman <chayimfr@gmail.com> | 2024-12-04 03:15:32 +0200 |
| commit | bc003049cfe3c85bfc3069ae8e76899efa6d08d1 (patch) | |
| tree | a612479af9b975477f6b3c544850837a6d5160e9 | |
| parent | cc4ffa7d6fdb61c6c0182ac4efc336e2b2991753 (diff) | |
| download | rust-bc003049cfe3c85bfc3069ae8e76899efa6d08d1.tar.gz rust-bc003049cfe3c85bfc3069ae8e76899efa6d08d1.zip | |
Fixed another bug with glob imports
When a glob import overriding the visibility of a previous glob import was not properly resolved when the items are only available in the next fixpoint iteration. The bug was hidden until #18390.
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs | 9 | ||||
| -rw-r--r-- | src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs | 39 |
2 files changed, 46 insertions, 2 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs index a37e3c70e22..98b08bcf708 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs @@ -910,8 +910,13 @@ impl DefCollector<'_> { self.update(module_id, &items, vis, Some(ImportType::Glob(id))); // record the glob import in case we add further items let glob = self.glob_imports.entry(m.local_id).or_default(); - if !glob.iter().any(|(mid, _, _)| *mid == module_id) { - glob.push((module_id, vis, id)); + match glob.iter_mut().find(|(mid, _, _)| *mid == module_id) { + None => glob.push((module_id, vis, id)), + Some((_, old_vis, _)) => { + if let Some(new_vis) = old_vis.max(vis, &self.def_map) { + *old_vis = new_vis; + } + } } } } diff --git a/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs b/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs index 543ab41cd59..8963a576794 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs @@ -451,3 +451,42 @@ mod glob_target { "#]], ); } + +#[test] +fn regression_18580() { + check( + r#" +pub mod libs { + pub struct Placeholder; +} + +pub mod reexport_2 { + use reexport_1::*; + pub use reexport_1::*; + + pub mod reexport_1 { + pub use crate::libs::*; + } +} + +use reexport_2::*; +"#, + expect![[r#" + crate + Placeholder: t v + libs: t + reexport_1: t + reexport_2: t + + crate::libs + Placeholder: t v + + crate::reexport_2 + Placeholder: t v + reexport_1: t + + crate::reexport_2::reexport_1 + Placeholder: t v + "#]], + ); +} |
