]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #34963 - petrochenkov:useerr, r=jseyfried
authorManish Goregaokar <manishsmail@gmail.com>
Thu, 28 Jul 2016 10:50:10 +0000 (16:20 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Thu, 28 Jul 2016 15:03:06 +0000 (20:33 +0530)
resolve: Fix ICE and extra diagnostics happening when unresolved imports are used in patterns

Closes https://github.com/rust-lang/rust/issues/34933

r? @jseyfried

src/librustc_resolve/lib.rs
src/test/compile-fail/unresolved-import-recovery.rs [new file with mode: 0644]

index aa8c706ea1e27b9cb73978f7248864c3627ee7e8..88cd29a3ccfa721b11e0dc0df3a1a988dbf09158 100644 (file)
@@ -2274,7 +2274,7 @@ fn resolve_pattern_path<ExpectedFn>(&mut self,
         let resolution = if let Some(resolution) = self.resolve_possibly_assoc_item(pat_id,
                                                                         qself, path, namespace) {
             if resolution.depth == 0 {
-                if expected_fn(resolution.base_def) {
+                if expected_fn(resolution.base_def) || resolution.base_def == Def::Err {
                     resolution
                 } else {
                     resolve_error(
@@ -2345,7 +2345,7 @@ fn resolve_pattern(&mut self,
                                 );
                                 None
                             }
-                            Def::Local(..) | Def::Upvar(..) | Def::Fn(..) => {
+                            Def::Local(..) | Def::Upvar(..) | Def::Fn(..) | Def::Err => {
                                 // These entities are explicitly allowed
                                 // to be shadowed by fresh bindings.
                                 None
diff --git a/src/test/compile-fail/unresolved-import-recovery.rs b/src/test/compile-fail/unresolved-import-recovery.rs
new file mode 100644 (file)
index 0000000..8173f69
--- /dev/null
@@ -0,0 +1,27 @@
+// 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.
+
+// Check that unresolved imports do not create additional errors and ICEs
+
+mod m {
+    pub use unresolved; //~ ERROR unresolved import `unresolved`
+
+    fn f() {
+        let unresolved = 0; // OK
+    }
+}
+
+fn main() {
+    match 0u8 {
+        m::unresolved => {} // OK
+        m::unresolved(..) => {} // OK
+        m::unresolved{..} => {} // OK
+    }
+}