Skip to content

Commit 2ea922a

Browse files
committed
Auto merge of #51696 - estebank:fuzzy-ice-ice, r=oli-obk
Accept `TyError` in patterns to avoid ICE on bad input Fix #50585.
2 parents 2db44b6 + fe5710a commit 2ea922a

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/librustc_mir/hair/pattern/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,16 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
505505
let def = self.tables.qpath_def(qpath, pat.hir_id);
506506
let adt_def = match ty.sty {
507507
ty::TyAdt(adt_def, _) => adt_def,
508-
_ => span_bug!(pat.span, "tuple struct pattern not applied to an ADT"),
508+
ty::TyError => { // Avoid ICE (#50585)
509+
return Pattern {
510+
span: pat.span,
511+
ty,
512+
kind: Box::new(PatternKind::Wild),
513+
};
514+
}
515+
_ => span_bug!(pat.span,
516+
"tuple struct pattern not applied to an ADT {:?}",
517+
ty.sty),
509518
};
510519
let variant_def = adt_def.variant_of_def(def);
511520

@@ -637,6 +646,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
637646
let substs = match ty.sty {
638647
ty::TyAdt(_, substs) |
639648
ty::TyFnDef(_, substs) => substs,
649+
ty::TyError => { // Avoid ICE (#50585)
650+
return PatternKind::Wild;
651+
}
640652
_ => bug!("inappropriate type for def: {:?}", ty.sty),
641653
};
642654
PatternKind::Variant {

src/test/ui/issue-50585.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
|y: Vec<[(); for x in 0..2 {}]>| {};
13+
//~^ ERROR mismatched types
14+
}

src/test/ui/issue-50585.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-50585.rs:12:18
3+
|
4+
LL | fn main() {
5+
| - expected `()` because of default return type
6+
LL | |y: Vec<[(); for x in 0..2 {}]>| {};
7+
| ^^^^^^^^^^^^^^^^ expected usize, found ()
8+
|
9+
= note: expected type `usize`
10+
found type `()`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)