Skip to content

Commit 3d117cf

Browse files
committed
auto merge of #12639 : luqmana/rust/struct-variant-pat, r=pcwalton
We weren't passing the node id for the enum and hence it couldn't retrieve the field types for the struct variant we were trying to destructure. Fixes #11577.
2 parents d60e43d + 715e618 commit 3d117cf

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/librustc/middle/trans/_match.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ fn compile_submatch_continue<'r,
15281528
Some(ref rec_fields) => {
15291529
let pat_ty = node_id_type(bcx, pat_id);
15301530
let pat_repr = adt::represent_type(bcx.ccx(), pat_ty);
1531-
expr::with_field_tys(tcx, pat_ty, None, |discr, field_tys| {
1531+
expr::with_field_tys(tcx, pat_ty, Some(pat_id), |discr, field_tys| {
15321532
let rec_vals = rec_fields.map(|field_name| {
15331533
let ix = ty::field_idx_strict(tcx, field_name.name, field_tys);
15341534
adt::trans_field_ptr(bcx, pat_repr, val, discr, ix)
@@ -2208,7 +2208,7 @@ fn bind_irrefutable_pat<'a>(
22082208
let tcx = bcx.tcx();
22092209
let pat_ty = node_id_type(bcx, pat.id);
22102210
let pat_repr = adt::represent_type(bcx.ccx(), pat_ty);
2211-
expr::with_field_tys(tcx, pat_ty, None, |discr, field_tys| {
2211+
expr::with_field_tys(tcx, pat_ty, Some(pat.id), |discr, field_tys| {
22122212
for f in fields.iter() {
22132213
let ix = ty::field_idx_strict(tcx, f.ident.name, field_tys);
22142214
let fldptr = adt::trans_field_ptr(bcx, pat_repr, val,

src/test/run-pass/issue-11577.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 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+
#[feature(struct_variant)];
12+
13+
// Destructuring struct variants would ICE where regular structs wouldn't
14+
15+
enum Foo {
16+
VBar { num: int }
17+
}
18+
19+
struct SBar { num: int }
20+
21+
pub fn main() {
22+
let vbar = VBar { num: 1 };
23+
let VBar { num } = vbar;
24+
assert_eq!(num, 1);
25+
26+
let sbar = SBar { num: 2 };
27+
let SBar { num } = sbar;
28+
assert_eq!(num, 2);
29+
}

0 commit comments

Comments
 (0)