]> git.lizzy.rs Git - rust.git/commitdiff
resolve: Fix an ICE in import validation
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Fri, 28 Dec 2018 02:20:11 +0000 (05:20 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Fri, 28 Dec 2018 02:43:31 +0000 (05:43 +0300)
src/librustc_resolve/resolve_imports.rs
src/test/ui/rust-2018/uniform-paths/auxiliary/issue-56596.rs [new file with mode: 0644]
src/test/ui/rust-2018/uniform-paths/issue-56596.rs [new file with mode: 0644]
src/test/ui/rust-2018/uniform-paths/issue-56596.stderr [new file with mode: 0644]

index 9a7b8c24993c6f3b7addef96f2ac58a6dfe673f5..5830aa3713d830d8d0f5c21c04f8dfcdbe4561b9 100644 (file)
@@ -223,11 +223,6 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
         }
 
         let check_usable = |this: &mut Self, binding: &'a NameBinding<'a>| {
-            if let Some(blacklisted_binding) = this.blacklisted_binding {
-                if ptr::eq(binding, blacklisted_binding) {
-                    return Err((Determined, Weak::No));
-                }
-            }
             // `extern crate` are always usable for backwards compatibility, see issue #37020,
             // remove this together with `PUB_USE_OF_PRIVATE_EXTERN_CRATE`.
             let usable = this.is_accessible(binding.vis) || binding.is_extern_crate();
@@ -235,7 +230,18 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
         };
 
         if record_used {
-            return resolution.binding.ok_or((Determined, Weak::No)).and_then(|binding| {
+            return resolution.binding.and_then(|binding| {
+                // If the primary binding is blacklisted, search further and return the shadowed
+                // glob binding if it exists. What we really want here is having two separate
+                // scopes in a module - one for non-globs and one for globs, but until that's done
+                // use this hack to avoid inconsistent resolution ICEs during import validation.
+                if let Some(blacklisted_binding) = self.blacklisted_binding {
+                    if ptr::eq(binding, blacklisted_binding) {
+                        return resolution.shadowed_glob;
+                    }
+                }
+                Some(binding)
+            }).ok_or((Determined, Weak::No)).and_then(|binding| {
                 if self.last_import_segment && check_usable(self, binding).is_err() {
                     Err((Determined, Weak::No))
                 } else {
diff --git a/src/test/ui/rust-2018/uniform-paths/auxiliary/issue-56596.rs b/src/test/ui/rust-2018/uniform-paths/auxiliary/issue-56596.rs
new file mode 100644 (file)
index 0000000..bc010a3
--- /dev/null
@@ -0,0 +1 @@
+// Nothing here
diff --git a/src/test/ui/rust-2018/uniform-paths/issue-56596.rs b/src/test/ui/rust-2018/uniform-paths/issue-56596.rs
new file mode 100644 (file)
index 0000000..5c40d78
--- /dev/null
@@ -0,0 +1,14 @@
+// edition:2018
+// compile-flags: --extern issue_56596
+// aux-build:issue-56596.rs
+
+#![feature(uniform_paths)]
+
+mod m {
+    pub mod issue_56596 {}
+}
+
+use m::*;
+use issue_56596; //~ ERROR `issue_56596` is ambiguous
+
+fn main() {}
diff --git a/src/test/ui/rust-2018/uniform-paths/issue-56596.stderr b/src/test/ui/rust-2018/uniform-paths/issue-56596.stderr
new file mode 100644 (file)
index 0000000..293d0ec
--- /dev/null
@@ -0,0 +1,18 @@
+error[E0659]: `issue_56596` is ambiguous (name vs any other name during import resolution)
+  --> $DIR/issue-56596.rs:12:5
+   |
+LL | use issue_56596; //~ ERROR `issue_56596` is ambiguous
+   |     ^^^^^^^^^^^ ambiguous name
+   |
+   = note: `issue_56596` could refer to an extern crate passed with `--extern`
+   = help: use `::issue_56596` to refer to this extern crate unambiguously
+note: `issue_56596` could also refer to the module imported here
+  --> $DIR/issue-56596.rs:11:5
+   |
+LL | use m::*;
+   |     ^^^^
+   = help: use `crate::issue_56596` to refer to this module unambiguously
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0659`.