Skip to content

Commit 245a0c5

Browse files
committed
item_like_imports: Make all visible items glob importable.
1 parent 097b6d6 commit 245a0c5

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/librustc_resolve/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,10 @@ impl<'a> Resolver<'a> {
32553255
vis.is_accessible_from(self.current_module.normal_ancestor_id, self)
32563256
}
32573257

3258+
fn is_accessible_from(&self, vis: ty::Visibility, module: Module<'a>) -> bool {
3259+
vis.is_accessible_from(module.normal_ancestor_id, self)
3260+
}
3261+
32583262
fn report_privacy_errors(&self) {
32593263
if self.privacy_errors.len() == 0 { return }
32603264
let mut reported_spans = FnvHashSet();

src/librustc_resolve/resolve_imports.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,11 @@ impl<'a> Resolver<'a> {
356356
};
357357

358358
// Define `binding` in `module`s glob importers.
359-
if binding.vis == ty::Visibility::Public {
360-
for directive in module.glob_importers.borrow_mut().iter() {
359+
for directive in module.glob_importers.borrow_mut().iter() {
360+
if match self.new_import_semantics {
361+
true => self.is_accessible_from(binding.vis, directive.parent),
362+
false => binding.vis == ty::Visibility::Public,
363+
} {
361364
let imported_binding = self.import(binding, directive);
362365
let _ = self.try_define(directive.parent, name, ns, imported_binding);
363366
}
@@ -708,7 +711,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
708711
resolution.borrow().binding().map(|binding| (*name, binding))
709712
}).collect::<Vec<_>>();
710713
for ((name, ns), binding) in bindings {
711-
if binding.pseudo_vis() == ty::Visibility::Public {
714+
if binding.pseudo_vis() == ty::Visibility::Public ||
715+
self.new_import_semantics && self.is_accessible(binding.vis) {
712716
let imported_binding = self.import(binding, directive);
713717
let _ = self.try_define(directive.parent, name, ns, imported_binding);
714718
}

src/test/compile-fail/imports/reexports.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ mod a {
1616

1717
mod a {
1818
pub use super::foo; //~ ERROR cannot be reexported
19+
pub use super::*; //~ ERROR must import something with the glob's visibility
1920
}
2021
}
2122

@@ -27,11 +28,17 @@ mod b {
2728
pub use super::foo; // This is OK since the value `foo` is visible enough.
2829
fn f(_: foo::S) {} // `foo` is imported in the type namespace (but not `pub` reexported).
2930
}
31+
32+
pub mod b {
33+
pub use super::*; // This is also OK since the value `foo` is visible enough.
34+
fn f(_: foo::S) {} // Again, the module `foo` is imported (but not `pub` reexported).
35+
}
3036
}
3137

3238
mod c {
3339
// Test that `foo` is not reexported.
3440
use b::a::foo::S; //~ ERROR `foo`
41+
use b::b::foo::S as T; //~ ERROR `foo`
3542
}
3643

3744
fn main() {}

0 commit comments

Comments
 (0)