]> git.lizzy.rs Git - rust.git/commitdiff
item_like_imports: Make all visible items glob importable.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Sat, 20 Aug 2016 00:33:06 +0000 (00:33 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Thu, 1 Sep 2016 22:30:26 +0000 (22:30 +0000)
src/librustc_resolve/lib.rs
src/librustc_resolve/resolve_imports.rs
src/test/compile-fail/imports/reexports.rs

index 8428507e686dfae015ff6b0b0a343101959d7160..12b708fa1a163c34bb44f3c2ca1d931dee84185d 100644 (file)
@@ -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();
index 189253348b0aa9aaab0f3986168ddc7f8c4d434f..4ab4ec4789d015cf47e2c1e8a34c0143e6010543 100644 (file)
@@ -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);
             }
index f8dbb4d444886c44d9135d76a94df46a9690de83..fc46b23351adf071f8e5893c71285ad495340452 100644 (file)
@@ -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() {}