Skip to content

Commit a455345

Browse files
committed
auto merge of #15951 : edwardw/rust/issue-15896, r=alexcrichton
Fix ICE when there's an incorrect enum variant constructor in match arm. Closes #15896.
2 parents 7f2e63e + c3f4c6d commit a455345

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/librustc/middle/typeck/check/_match.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,9 @@ pub fn check_struct_like_enum_variant_pat(pcx: &pat_ctxt,
390390
check_struct_pat_fields(pcx, span, fields, class_fields,
391391
variant_id, substitutions, etc);
392392
}
393-
Some(&def::DefStruct(..)) | Some(&def::DefVariant(..)) => {
393+
Some(&def::DefStruct(..)) |
394+
Some(&def::DefVariant(..)) |
395+
Some(&def::DefTy(..)) => {
394396
let name = pprust::path_to_string(path);
395397
span_err!(tcx.sess, span, E0028,
396398
"mismatched types: expected `{}` but found `{}`",

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

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2012-2014 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+
// Regression test for #15896. It used to ICE rustc.
12+
13+
fn main() {
14+
enum R { REB(()) }
15+
struct Tau { t: uint }
16+
enum E { B(R, Tau) }
17+
18+
let e = B(REB(()), Tau { t: 3 });
19+
let u = match e {
20+
B(
21+
Tau{t: x}, //~ ERROR mismatched types
22+
_) => x,
23+
};
24+
}

0 commit comments

Comments
 (0)