Skip to content

Commit 418d1bf

Browse files
committed
Fix ICE when a struct variant enum is imported from an external crate
Fixes the first case of #19340.
1 parent cf0b4e0 commit 418d1bf

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

src/librustc/metadata/decoder.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,14 +681,22 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
681681
let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
682682
item, tcx, cdata);
683683
let name = item_name(&*intr, item);
684-
let (ctor_ty, arg_tys) = match ctor_ty.sty {
684+
let (ctor_ty, arg_tys, arg_names) = match ctor_ty.sty {
685685
ty::ty_bare_fn(ref f) =>
686-
(Some(ctor_ty), f.sig.inputs.clone()),
687-
_ => // Nullary or struct enum variant.
688-
(None, get_struct_fields(intr.clone(), cdata, did.node)
686+
(Some(ctor_ty), f.sig.inputs.clone(), None),
687+
_ => { // Nullary or struct enum variant.
688+
let mut arg_names = Vec::new();
689+
let arg_tys = get_struct_fields(intr.clone(), cdata, did.node)
689690
.iter()
690-
.map(|field_ty| get_type(cdata, field_ty.id.node, tcx).ty)
691-
.collect())
691+
.map(|field_ty| {
692+
arg_names.push(ast::Ident::new(field_ty.name));
693+
get_type(cdata, field_ty.id.node, tcx).ty
694+
})
695+
.collect();
696+
let arg_names = if arg_names.len() == 0 { None } else { Some(arg_names) };
697+
698+
(None, arg_tys, arg_names)
699+
}
692700
};
693701
match variant_disr_val(item) {
694702
Some(val) => { disr_val = val; }
@@ -698,7 +706,7 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
698706
disr_val += 1;
699707
Rc::new(ty::VariantInfo {
700708
args: arg_tys,
701-
arg_names: None,
709+
arg_names: arg_names,
702710
ctor_ty: ctor_ty,
703711
name: name,
704712
// I'm not even sure if we encode visibility

src/test/auxiliary/issue-19340-1.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
pub enum Homura {
12+
Madoka { name: String },
13+
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
// aux-build:issue-19340-1.rs
12+
13+
extern crate "issue-19340-1" as lib;
14+
15+
use lib::Homura;
16+
17+
fn main() {
18+
let homura = Homura::Madoka { name: "Kaname".into_string() };
19+
20+
match homura {
21+
Homura::Madoka { name } => (),
22+
};
23+
}

0 commit comments

Comments
 (0)