Skip to content

Commit bc00304

Browse files
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 rust-lang#18390.
1 parent cc4ffa7 commit bc00304

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,13 @@ impl DefCollector<'_> {
910910
self.update(module_id, &items, vis, Some(ImportType::Glob(id)));
911911
// record the glob import in case we add further items
912912
let glob = self.glob_imports.entry(m.local_id).or_default();
913-
if !glob.iter().any(|(mid, _, _)| *mid == module_id) {
914-
glob.push((module_id, vis, id));
913+
match glob.iter_mut().find(|(mid, _, _)| *mid == module_id) {
914+
None => glob.push((module_id, vis, id)),
915+
Some((_, old_vis, _)) => {
916+
if let Some(new_vis) = old_vis.max(vis, &self.def_map) {
917+
*old_vis = new_vis;
918+
}
919+
}
915920
}
916921
}
917922
}

src/tools/rust-analyzer/crates/hir-def/src/nameres/tests/globs.rs

+39
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,42 @@ mod glob_target {
451451
"#]],
452452
);
453453
}
454+
455+
#[test]
456+
fn regression_18580() {
457+
check(
458+
r#"
459+
pub mod libs {
460+
pub struct Placeholder;
461+
}
462+
463+
pub mod reexport_2 {
464+
use reexport_1::*;
465+
pub use reexport_1::*;
466+
467+
pub mod reexport_1 {
468+
pub use crate::libs::*;
469+
}
470+
}
471+
472+
use reexport_2::*;
473+
"#,
474+
expect![[r#"
475+
crate
476+
Placeholder: t v
477+
libs: t
478+
reexport_1: t
479+
reexport_2: t
480+
481+
crate::libs
482+
Placeholder: t v
483+
484+
crate::reexport_2
485+
Placeholder: t v
486+
reexport_1: t
487+
488+
crate::reexport_2::reexport_1
489+
Placeholder: t v
490+
"#]],
491+
);
492+
}

0 commit comments

Comments
 (0)