提交 245a0c55 编写于 作者: J Jeffrey Seyfried

item_like_imports: Make all visible items glob importable.

上级 097b6d62
......@@ -3255,6 +3255,10 @@ fn is_accessible(&self, vis: ty::Visibility) -> bool {
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 @@ fn update_resolution<T, F>(&mut self, module: Module<'a>, name: Name, ns: Namesp
};
// 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 @@ fn resolve_glob_import(&mut self, directive: &'b ImportDirective<'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 foo {}
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 @@ pub mod a {
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() {}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册