Skip to content

Commit aad1f3c

Browse files
committed
item_like_imports: Allow glob imports to be shadowed by items and single imports.
1 parent efc0bea commit aad1f3c

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -690,15 +690,21 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
690690
};
691691

692692
// Report conflicts
693-
for duplicate_glob in resolution.duplicate_globs.iter() {
694-
// FIXME #31337: We currently allow items to shadow glob-imported re-exports.
695-
if !binding.is_import() {
696-
if let NameBindingKind::Import { binding, .. } = duplicate_glob.kind {
697-
if binding.is_import() { continue }
693+
if !self.new_import_semantics {
694+
for duplicate_glob in resolution.duplicate_globs.iter() {
695+
// FIXME #31337: We currently allow items to shadow glob-imported re-exports.
696+
if !binding.is_import() {
697+
if let NameBindingKind::Import { binding, .. } = duplicate_glob.kind {
698+
if binding.is_import() { continue }
699+
}
698700
}
699-
}
700701

701-
self.report_conflict(module, name, ns, duplicate_glob, binding);
702+
self.report_conflict(module, name, ns, duplicate_glob, binding);
703+
}
704+
} else if binding.is_glob_import() {
705+
for duplicate_glob in resolution.duplicate_globs.iter() {
706+
self.report_conflict(module, name, ns, duplicate_glob, binding);
707+
}
702708
}
703709

704710
if binding.vis == ty::Visibility::Public &&

src/test/run-pass/imports.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,46 @@ mod a {
2121
}
2222
}
2323

24+
mod foo { pub fn f() {} }
25+
mod bar { pub fn f() {} }
26+
27+
pub fn f() -> bool { true }
28+
29+
// Items and explicit imports shadow globs.
30+
fn g() {
31+
use foo::*;
32+
use bar::*;
33+
fn f() -> bool { true }
34+
let _: bool = f();
35+
}
36+
37+
fn h() {
38+
use foo::*;
39+
use bar::*;
40+
use f;
41+
let _: bool = f();
42+
}
43+
44+
// Here, there appears to be shadowing but isn't because of namespaces.
45+
mod b {
46+
use foo::*; // This imports `f` in the value namespace.
47+
use super::b as f; // This imports `f` only in the type namespace,
48+
fn test() { self::f(); } // so the glob isn't shadowed.
49+
}
50+
51+
// Here, there is shadowing in one namespace, but not the other.
52+
mod c {
53+
mod test {
54+
pub fn f() {}
55+
pub mod f {}
56+
}
57+
use self::test::*; // This glob-imports `f` in both namespaces.
58+
mod f { pub fn f() {} } // This shadows the glob only in the value namespace.
59+
60+
fn test() {
61+
self::f(); // Check that the glob-imported value isn't shadowed.
62+
self::f::f(); // Check that the glob-imported module is shadowed.
63+
}
64+
}
65+
2466
fn main() {}

0 commit comments

Comments
 (0)