item_like_imports: Make all visible items glob importable.
This commit is contained in:
parent
097b6d62fc
commit
245a0c5530
@ -3255,6 +3255,10 @@ impl<'a> Resolver<'a> {
|
||||
vis.is_accessible_from(self.current_module.normal_ancestor_id, self)
|
||||
}
|
||||
|
||||
fn is_accessible_from(&self, vis: ty::Visibility, module: Module<'a>) -> bool {
|
||||
vis.is_accessible_from(module.normal_ancestor_id, self)
|
||||
}
|
||||
|
||||
fn report_privacy_errors(&self) {
|
||||
if self.privacy_errors.len() == 0 { return }
|
||||
let mut reported_spans = FnvHashSet();
|
||||
|
@ -356,8 +356,11 @@ impl<'a> Resolver<'a> {
|
||||
};
|
||||
|
||||
// Define `binding` in `module`s glob importers.
|
||||
if binding.vis == ty::Visibility::Public {
|
||||
for directive in module.glob_importers.borrow_mut().iter() {
|
||||
for directive in module.glob_importers.borrow_mut().iter() {
|
||||
if match self.new_import_semantics {
|
||||
true => self.is_accessible_from(binding.vis, directive.parent),
|
||||
false => binding.vis == ty::Visibility::Public,
|
||||
} {
|
||||
let imported_binding = self.import(binding, directive);
|
||||
let _ = self.try_define(directive.parent, name, ns, imported_binding);
|
||||
}
|
||||
@ -708,7 +711,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||
resolution.borrow().binding().map(|binding| (*name, binding))
|
||||
}).collect::<Vec<_>>();
|
||||
for ((name, ns), binding) in bindings {
|
||||
if binding.pseudo_vis() == ty::Visibility::Public {
|
||||
if binding.pseudo_vis() == ty::Visibility::Public ||
|
||||
self.new_import_semantics && self.is_accessible(binding.vis) {
|
||||
let imported_binding = self.import(binding, directive);
|
||||
let _ = self.try_define(directive.parent, name, ns, imported_binding);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ mod a {
|
||||
|
||||
mod a {
|
||||
pub use super::foo; //~ ERROR cannot be reexported
|
||||
pub use super::*; //~ ERROR must import something with the glob's visibility
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,11 +28,17 @@ mod b {
|
||||
pub use super::foo; // This is OK since the value `foo` is visible enough.
|
||||
fn f(_: foo::S) {} // `foo` is imported in the type namespace (but not `pub` reexported).
|
||||
}
|
||||
|
||||
pub mod b {
|
||||
pub use super::*; // This is also OK since the value `foo` is visible enough.
|
||||
fn f(_: foo::S) {} // Again, the module `foo` is imported (but not `pub` reexported).
|
||||
}
|
||||
}
|
||||
|
||||
mod c {
|
||||
// Test that `foo` is not reexported.
|
||||
use b::a::foo::S; //~ ERROR `foo`
|
||||
use b::b::foo::S as T; //~ ERROR `foo`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user