Skip to content

Commit f2a099b

Browse files
authored
Rollup merge of rust-lang#51789 - estebank:issue-50577, r=oli-obk
Don't ICE when performing `lower_pattern_unadjusted` on a `TyError` Fix rust-lang#50577. CC rust-lang#51696. r? @oli-obk
2 parents 8014713 + 7aab3bf commit f2a099b

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

src/librustc_mir/hair/pattern/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
416416
}
417417

418418
PatKind::Slice(ref prefix, ref slice, ref suffix) => {
419-
let ty = self.tables.node_id_to_type(pat.hir_id);
420419
match ty.sty {
421420
ty::TyRef(_, ty, _) =>
422421
PatternKind::Deref {
@@ -427,11 +426,12 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
427426
pat.span, ty, prefix, slice, suffix))
428427
},
429428
},
430-
431429
ty::TySlice(..) |
432430
ty::TyArray(..) =>
433431
self.slice_or_array_pattern(pat.span, ty, prefix, slice, suffix),
434-
432+
ty::TyError => { // Avoid ICE
433+
return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) };
434+
}
435435
ref sty =>
436436
span_bug!(
437437
pat.span,
@@ -441,7 +441,6 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
441441
}
442442

443443
PatKind::Tuple(ref subpatterns, ddpos) => {
444-
let ty = self.tables.node_id_to_type(pat.hir_id);
445444
match ty.sty {
446445
ty::TyTuple(ref tys) => {
447446
let subpatterns =
@@ -455,7 +454,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
455454

456455
PatternKind::Leaf { subpatterns: subpatterns }
457456
}
458-
457+
ty::TyError => { // Avoid ICE (#50577)
458+
return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) };
459+
}
459460
ref sty => span_bug!(pat.span, "unexpected type for tuple pattern: {:?}", sty),
460461
}
461462
}
@@ -464,6 +465,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
464465
let var_ty = self.tables.node_id_to_type(pat.hir_id);
465466
let region = match var_ty.sty {
466467
ty::TyRef(r, _, _) => Some(r),
468+
ty::TyError => { // Avoid ICE
469+
return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) };
470+
}
467471
_ => None,
468472
};
469473
let bm = *self.tables.pat_binding_modes().get(pat.hir_id)
@@ -505,12 +509,8 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
505509
let def = self.tables.qpath_def(qpath, pat.hir_id);
506510
let adt_def = match ty.sty {
507511
ty::TyAdt(adt_def, _) => adt_def,
508-
ty::TyError => { // Avoid ICE (#50585)
509-
return Pattern {
510-
span: pat.span,
511-
ty,
512-
kind: Box::new(PatternKind::Wild),
513-
};
512+
ty::TyError => { // Avoid ICE (#50585)
513+
return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) };
514514
}
515515
_ => span_bug!(pat.span,
516516
"tuple struct pattern not applied to an ADT {:?}",

src/test/ui/issue-50577.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
enum Foo {
13+
Drop = assert_eq!(1, 1)
14+
}
15+
}

src/test/ui/issue-50577.stderr

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0317]: if may be missing an else clause
2+
--> $DIR/issue-50577.rs:13:16
3+
|
4+
LL | Drop = assert_eq!(1, 1)
5+
| ^^^^^^^^^^^^^^^^ expected (), found isize
6+
|
7+
= note: expected type `()`
8+
found type `isize`
9+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0317`.

0 commit comments

Comments
 (0)