about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-06-23 06:56:12 +0000
committerbors <bors@rust-lang.org>2018-06-23 06:56:12 +0000
commit2ea922a96d676ff84cd78421d314e6aac305b5e9 (patch)
tree781970b77cf3b20ffaeacecbfd2cf156c3c77610
parent2db44b62e764e01cb889e89ef60231ad9ab3b4c9 (diff)
parentfe5710a25ec9559d3c72dea609d0a86b79ec574d (diff)
downloadrust-2ea922a96d676ff84cd78421d314e6aac305b5e9.tar.gz
rust-2ea922a96d676ff84cd78421d314e6aac305b5e9.zip
Auto merge of #51696 - estebank:fuzzy-ice-ice, r=oli-obk
Accept `TyError` in patterns to avoid ICE on bad input

Fix #50585.
-rw-r--r--src/librustc_mir/hair/pattern/mod.rs14
-rw-r--r--src/test/ui/issue-50585.rs14
-rw-r--r--src/test/ui/issue-50585.stderr14
3 files changed, 41 insertions, 1 deletions
diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs
index 7dae79530c4..2b1422773c1 100644
--- a/src/librustc_mir/hair/pattern/mod.rs
+++ b/src/librustc_mir/hair/pattern/mod.rs
@@ -505,7 +505,16 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
                 let def = self.tables.qpath_def(qpath, pat.hir_id);
                 let adt_def = match ty.sty {
                     ty::TyAdt(adt_def, _) => adt_def,
-                    _ => span_bug!(pat.span, "tuple struct pattern not applied to an ADT"),
+                    ty::TyError => {  // Avoid ICE (#50585)
+                        return Pattern {
+                            span: pat.span,
+                            ty,
+                            kind: Box::new(PatternKind::Wild),
+                        };
+                    }
+                    _ => span_bug!(pat.span,
+                                   "tuple struct pattern not applied to an ADT {:?}",
+                                   ty.sty),
                 };
                 let variant_def = adt_def.variant_of_def(def);
 
@@ -637,6 +646,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
                     let substs = match ty.sty {
                         ty::TyAdt(_, substs) |
                         ty::TyFnDef(_, substs) => substs,
+                        ty::TyError => {  // Avoid ICE (#50585)
+                            return PatternKind::Wild;
+                        }
                         _ => bug!("inappropriate type for def: {:?}", ty.sty),
                     };
                     PatternKind::Variant {
diff --git a/src/test/ui/issue-50585.rs b/src/test/ui/issue-50585.rs
new file mode 100644
index 00000000000..0c063d4cdb0
--- /dev/null
+++ b/src/test/ui/issue-50585.rs
@@ -0,0 +1,14 @@
+// Copyright 2018 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.
+
+fn main() {
+    |y: Vec<[(); for x in 0..2 {}]>| {};
+    //~^ ERROR mismatched types
+}
diff --git a/src/test/ui/issue-50585.stderr b/src/test/ui/issue-50585.stderr
new file mode 100644
index 00000000000..3f9328de93f
--- /dev/null
+++ b/src/test/ui/issue-50585.stderr
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+  --> $DIR/issue-50585.rs:12:18
+   |
+LL | fn main() {
+   |           - expected `()` because of default return type
+LL |     |y: Vec<[(); for x in 0..2 {}]>| {};
+   |                  ^^^^^^^^^^^^^^^^ expected usize, found ()
+   |
+   = note: expected type `usize`
+              found type `()`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.