]> git.lizzy.rs Git - rust.git/commitdiff
item_like_imports: Allow glob imports to be shadowed by items and single imports.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Thu, 18 Aug 2016 20:33:24 +0000 (20:33 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Thu, 1 Sep 2016 22:30:24 +0000 (22:30 +0000)
src/librustc_resolve/resolve_imports.rs
src/test/run-pass/imports.rs

index d6aae23947f2e7676472ff81e0e155ce770771c3..c7cb3a351784dff8b6288314cfe656e13e6e2375 100644 (file)
@@ -690,15 +690,21 @@ fn finalize_resolutions_in(&mut self, module: Module<'b>) {
             };
 
             // Report conflicts
-            for duplicate_glob in resolution.duplicate_globs.iter() {
-                // FIXME #31337: We currently allow items to shadow glob-imported re-exports.
-                if !binding.is_import() {
-                    if let NameBindingKind::Import { binding, .. } = duplicate_glob.kind {
-                        if binding.is_import() { continue }
+            if !self.new_import_semantics {
+                for duplicate_glob in resolution.duplicate_globs.iter() {
+                    // FIXME #31337: We currently allow items to shadow glob-imported re-exports.
+                    if !binding.is_import() {
+                        if let NameBindingKind::Import { binding, .. } = duplicate_glob.kind {
+                            if binding.is_import() { continue }
+                        }
                     }
-                }
 
-                self.report_conflict(module, name, ns, duplicate_glob, binding);
+                    self.report_conflict(module, name, ns, duplicate_glob, binding);
+                }
+            } else if binding.is_glob_import() {
+                for duplicate_glob in resolution.duplicate_globs.iter() {
+                    self.report_conflict(module, name, ns, duplicate_glob, binding);
+                }
             }
 
             if binding.vis == ty::Visibility::Public &&
index 900e0b69ebba5389e686558cfd54136142c1260d..df4961c074ae1279eb1be6d6196c9e790b608562 100644 (file)
@@ -21,4 +21,46 @@ mod b {
     }
 }
 
+mod foo { pub fn f() {} }
+mod bar { pub fn f() {} }
+
+pub fn f() -> bool { true }
+
+// Items and explicit imports shadow globs.
+fn g() {
+    use foo::*;
+    use bar::*;
+    fn f() -> bool { true }
+    let _: bool = f();
+}
+
+fn h() {
+    use foo::*;
+    use bar::*;
+    use f;
+    let _: bool = f();
+}
+
+// Here, there appears to be shadowing but isn't because of namespaces.
+mod b {
+    use foo::*; // This imports `f` in the value namespace.
+    use super::b as f; // This imports `f` only in the type namespace,
+    fn test() { self::f(); } // so the glob isn't shadowed.
+}
+
+// Here, there is shadowing in one namespace, but not the other.
+mod c {
+    mod test {
+        pub fn f() {}
+        pub mod f {}
+    }
+    use self::test::*; // This glob-imports `f` in both namespaces.
+    mod f { pub fn f() {} } // This shadows the glob only in the value namespace.
+
+    fn test() {
+        self::f(); // Check that the glob-imported value isn't shadowed.
+        self::f::f(); // Check that the glob-imported module is shadowed.
+    }
+}
+
 fn main() {}