about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-20 00:33:06 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-09-01 22:30:26 +0000
commit245a0c5530f8d4d251bcef2d7b8de2fa19f442bf (patch)
tree11690ae6f31abbe9ae8ca35f3595169eccdc7952
parent097b6d62fc7431b322b46b3a0e9f36134c13dd82 (diff)
downloadrust-245a0c5530f8d4d251bcef2d7b8de2fa19f442bf.tar.gz
rust-245a0c5530f8d4d251bcef2d7b8de2fa19f442bf.zip
item_like_imports: Make all visible items glob importable.
-rw-r--r--src/librustc_resolve/lib.rs4
-rw-r--r--src/librustc_resolve/resolve_imports.rs10
-rw-r--r--src/test/compile-fail/imports/reexports.rs7
3 files changed, 18 insertions, 3 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 8428507e686..12b708fa1a1 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -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();
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index 189253348b0..4ab4ec4789d 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -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);
             }
diff --git a/src/test/compile-fail/imports/reexports.rs b/src/test/compile-fail/imports/reexports.rs
index f8dbb4d4448..fc46b23351a 100644
--- a/src/test/compile-fail/imports/reexports.rs
+++ b/src/test/compile-fail/imports/reexports.rs
@@ -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() {}