]> git.lizzy.rs Git - rust.git/commitdiff
item_like_imports: Treat private imports like private items.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Sat, 20 Aug 2016 00:57:19 +0000 (00:57 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Thu, 1 Sep 2016 22:30:21 +0000 (22:30 +0000)
src/librustc_resolve/resolve_imports.rs
src/test/run-pass/imports.rs [new file with mode: 0644]

index f02e9b048dea76052705dbee6ad7339fea58581a..d6aae23947f2e7676472ff81e0e155ce770771c3 100644 (file)
@@ -167,8 +167,10 @@ pub fn resolve_name_in_module(&mut self,
             _ => return Failed(None), // This happens when there is a cycle of imports
         };
 
+        let new_import_semantics = self.new_import_semantics;
         let is_disallowed_private_import = |binding: &NameBinding| {
-            !allow_private_imports && binding.vis != ty::Visibility::Public && binding.is_import()
+            !new_import_semantics && !allow_private_imports && // disallowed
+            binding.vis != ty::Visibility::Public && binding.is_import() // non-`pub` import
         };
 
         if let Some(span) = record_used {
diff --git a/src/test/run-pass/imports.rs b/src/test/run-pass/imports.rs
new file mode 100644 (file)
index 0000000..900e0b6
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(item_like_imports)]
+#![allow(unused)]
+
+// Like other items, private imports can be imported and used non-lexically in paths.
+mod a {
+    use a as foo;
+    use self::foo::foo as bar;
+
+    mod b {
+        use super::bar;
+    }
+}
+
+fn main() {}