about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-20 03:28:35 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-09-01 22:30:26 +0000
commitf582fa327e210ea5bf91d6b8f174f35fc9006054 (patch)
treef5ffd57f363aef3e3eda96ef8d815cd649434c0c /src
parent245a0c5530f8d4d251bcef2d7b8de2fa19f442bf (diff)
downloadrust-f582fa327e210ea5bf91d6b8f174f35fc9006054.tar.gz
rust-f582fa327e210ea5bf91d6b8f174f35fc9006054.zip
item_like_imports: Allow multiple glob imports of the same item.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_resolve/resolve_imports.rs20
-rw-r--r--src/test/compile-fail/imports/duplicate.rs38
2 files changed, 53 insertions, 5 deletions
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index 4ab4ec4789d..495bdcb7dfd 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -317,10 +317,17 @@ impl<'a> Resolver<'a> {
         where T: ToNameBinding<'a>
     {
         let binding = self.arenas.alloc_name_binding(binding.to_name_binding());
-        self.update_resolution(module, name, ns, |_, resolution| {
+        self.update_resolution(module, name, ns, |this, resolution| {
             if let Some(old_binding) = resolution.binding {
                 if binding.is_glob_import() {
-                    resolution.duplicate_globs.push(binding);
+                    if !this.new_import_semantics || !old_binding.is_glob_import() {
+                        resolution.duplicate_globs.push(binding);
+                    } else if binding.def() != old_binding.def() {
+                        resolution.duplicate_globs.push(binding);
+                    } else if !old_binding.vis.is_at_least(binding.vis, this) {
+                        // We are glob-importing the same item but with greater visibility.
+                        resolution.binding = Some(binding);
+                    }
                 } else if old_binding.is_glob_import() {
                     resolution.duplicate_globs.push(old_binding);
                     resolution.binding = Some(binding);
@@ -344,14 +351,17 @@ impl<'a> Resolver<'a> {
         // during which the resolution might end up getting re-defined via a glob cycle.
         let (binding, t) = {
             let mut resolution = &mut *self.resolution(module, name, ns).borrow_mut();
-            let was_known = resolution.binding().is_some();
+            let old_binding = resolution.binding();
 
             let t = f(self, resolution);
 
-            if was_known { return t; }
             match resolution.binding() {
-                Some(binding) => (binding, t),
+                _ if !self.new_import_semantics && old_binding.is_some() => return t,
                 None => return t,
+                Some(binding) => match old_binding {
+                    Some(old_binding) if old_binding as *const _ == binding as *const _ => return t,
+                    _ => (binding, t),
+                }
             }
         };
 
diff --git a/src/test/compile-fail/imports/duplicate.rs b/src/test/compile-fail/imports/duplicate.rs
new file mode 100644
index 00000000000..0b5963dd893
--- /dev/null
+++ b/src/test/compile-fail/imports/duplicate.rs
@@ -0,0 +1,38 @@
+// 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)]
+
+mod a {
+    pub fn foo() {}
+}
+
+mod b {
+    pub fn foo() {}
+}
+
+mod c {
+    pub use a::foo;
+}
+
+mod d {
+    use a::foo; //~ NOTE previous import
+    use a::foo; //~ ERROR `foo` has already been imported
+                //~| NOTE already imported
+}
+
+mod e {
+    pub use a::*;
+    pub use c::*; // ok
+}
+
+fn main() {
+    e::foo();
+}