Skip to content

Commit 086c949

Browse files
committed
Fix ICE when a struct variant enum contains multiple fields
Fixes the second case of #19340.
1 parent 418d1bf commit 086c949

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/librustc/middle/borrowck/fragments.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,10 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
346346
Rc<LoanPath<'tcx>>)>) {
347347
let parent_ty = parent_lp.to_type();
348348

349-
let add_fragment_sibling_local = |field_name| {
349+
let add_fragment_sibling_local = |field_name, variant_did| {
350350
add_fragment_sibling_core(
351-
this, tcx, gathered_fragments, parent_lp.clone(), mc, field_name, origin_lp);
351+
this, tcx, gathered_fragments, parent_lp.clone(), mc, field_name, origin_lp,
352+
variant_did);
352353
};
353354

354355
match (&parent_ty.sty, enum_variant_info) {
@@ -363,7 +364,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
363364
for i in range(0, tuple_len) {
364365
if i == tuple_idx { continue }
365366
let field_name = mc::PositionalField(i);
366-
add_fragment_sibling_local(field_name);
367+
add_fragment_sibling_local(field_name, None);
367368
}
368369
}
369370

@@ -376,7 +377,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
376377
continue;
377378
}
378379
let field_name = mc::NamedField(f.name);
379-
add_fragment_sibling_local(field_name);
380+
add_fragment_sibling_local(field_name, None);
380381
}
381382
}
382383
mc::PositionalField(tuple_idx) => {
@@ -385,7 +386,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
385386
continue
386387
}
387388
let field_name = mc::PositionalField(i);
388-
add_fragment_sibling_local(field_name);
389+
add_fragment_sibling_local(field_name, None);
389390
}
390391
}
391392
}
@@ -414,7 +415,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
414415
continue;
415416
}
416417
let field_name = mc::NamedField(variant_arg_ident.name);
417-
add_fragment_sibling_local(field_name);
418+
add_fragment_sibling_local(field_name, Some(variant_info.id));
418419
}
419420
}
420421
mc::PositionalField(tuple_idx) => {
@@ -424,7 +425,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
424425
continue;
425426
}
426427
let field_name = mc::PositionalField(i);
427-
add_fragment_sibling_local(field_name);
428+
add_fragment_sibling_local(field_name, None);
428429
}
429430
}
430431
}
@@ -447,10 +448,11 @@ fn add_fragment_sibling_core<'tcx>(this: &MoveData<'tcx>,
447448
parent: Rc<LoanPath<'tcx>>,
448449
mc: mc::MutabilityCategory,
449450
new_field_name: mc::FieldName,
450-
origin_lp: &Rc<LoanPath<'tcx>>) -> MovePathIndex {
451+
origin_lp: &Rc<LoanPath<'tcx>>,
452+
enum_variant_did: Option<ast::DefId>) -> MovePathIndex {
451453
let opt_variant_did = match parent.kind {
452454
LpDowncast(_, variant_did) => Some(variant_did),
453-
LpVar(..) | LpUpvar(..) | LpExtend(..) => None,
455+
LpVar(..) | LpUpvar(..) | LpExtend(..) => enum_variant_did,
454456
};
455457

456458
let loan_path_elem = LpInterior(mc::InteriorField(new_field_name));

src/test/run-pass/issue-19340-2.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
enum Homura {
12+
Madoka {
13+
name: String,
14+
age: u32,
15+
},
16+
}
17+
18+
fn main() {
19+
let homura = Homura::Madoka {
20+
name: "Akemi".into_string(),
21+
age: 14,
22+
};
23+
24+
match homura {
25+
Homura::Madoka {
26+
name,
27+
age,
28+
} => (),
29+
};
30+
}

0 commit comments

Comments
 (0)