Skip to content

Commit 8c0fef8

Browse files
committed
Fix ICE in memory categorization of tuple patterns
1 parent 1f9423a commit 8c0fef8

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/librustc/middle/mem_categorization.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1145,8 +1145,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
11451145
}
11461146
}
11471147
Some(Def::Struct(..)) => {
1148-
let expected_len = match self.pat_ty(&pat) {
1149-
Ok(&ty::TyS{sty: ty::TyStruct(adt_def, _), ..}) => {
1148+
let expected_len = match self.pat_ty(&pat)?.sty {
1149+
ty::TyStruct(adt_def, _) => {
11501150
adt_def.struct_variant().fields.len()
11511151
}
11521152
ref ty => {
@@ -1196,8 +1196,8 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
11961196

11971197
PatKind::Tuple(ref subpats, ddpos) => {
11981198
// (p1, ..., pN)
1199-
let expected_len = match self.pat_ty(&pat) {
1200-
Ok(&ty::TyS{sty: ty::TyTuple(ref tys), ..}) => tys.len(),
1199+
let expected_len = match self.pat_ty(&pat)?.sty {
1200+
ty::TyTuple(ref tys) => tys.len(),
12011201
ref ty => span_bug!(pat.span, "tuple pattern unexpected type {:?}", ty),
12021202
};
12031203
for (i, subpat) in subpats.iter().enumerate_and_adjust(expected_len, ddpos) {

src/test/compile-fail/issue-34334.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 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+
let sr: Vec<(u32, _, _) = vec![]; //~ ERROR expected one of `+`, `,`, or `>`, found `=`
13+
let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect();
14+
//~^ ERROR unresolved name `sr`
15+
}

0 commit comments

Comments
 (0)