about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBarosl Lee <vcs@barosl.com>2014-12-05 23:30:25 +0900
committerBarosl Lee <vcs@barosl.com>2014-12-12 03:38:11 +0900
commit418d1bfc9a3a71ce1beaced9ec6592ad614646b0 (patch)
tree741ee2f57f4495fc4a94c986da8ad612f4ea7cc3 /src
parentcf0b4e068227dd33fa15f3ffe24f29e0535d197f (diff)
downloadrust-418d1bfc9a3a71ce1beaced9ec6592ad614646b0.tar.gz
rust-418d1bfc9a3a71ce1beaced9ec6592ad614646b0.zip
Fix ICE when a struct variant enum is imported from an external crate
Fixes the first case of #19340.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/metadata/decoder.rs22
-rw-r--r--src/test/auxiliary/issue-19340-1.rs13
-rw-r--r--src/test/run-pass/issue-19340-1.rs23
3 files changed, 51 insertions, 7 deletions
diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs
index f352a28df69..37e05ac8a73 100644
--- a/src/librustc/metadata/decoder.rs
+++ b/src/librustc/metadata/decoder.rs
@@ -681,14 +681,22 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
         let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
                                 item, tcx, cdata);
         let name = item_name(&*intr, item);
-        let (ctor_ty, arg_tys) = match ctor_ty.sty {
+        let (ctor_ty, arg_tys, arg_names) = match ctor_ty.sty {
             ty::ty_bare_fn(ref f) =>
-                (Some(ctor_ty), f.sig.inputs.clone()),
-            _ => // Nullary or struct enum variant.
-                (None, get_struct_fields(intr.clone(), cdata, did.node)
+                (Some(ctor_ty), f.sig.inputs.clone(), None),
+            _ => { // Nullary or struct enum variant.
+                let mut arg_names = Vec::new();
+                let arg_tys = get_struct_fields(intr.clone(), cdata, did.node)
                     .iter()
-                    .map(|field_ty| get_type(cdata, field_ty.id.node, tcx).ty)
-                    .collect())
+                    .map(|field_ty| {
+                        arg_names.push(ast::Ident::new(field_ty.name));
+                        get_type(cdata, field_ty.id.node, tcx).ty
+                    })
+                    .collect();
+                let arg_names = if arg_names.len() == 0 { None } else { Some(arg_names) };
+
+                (None, arg_tys, arg_names)
+            }
         };
         match variant_disr_val(item) {
             Some(val) => { disr_val = val; }
@@ -698,7 +706,7 @@ pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::Nod
         disr_val += 1;
         Rc::new(ty::VariantInfo {
             args: arg_tys,
-            arg_names: None,
+            arg_names: arg_names,
             ctor_ty: ctor_ty,
             name: name,
             // I'm not even sure if we encode visibility
diff --git a/src/test/auxiliary/issue-19340-1.rs b/src/test/auxiliary/issue-19340-1.rs
new file mode 100644
index 00000000000..fc61b78d8a7
--- /dev/null
+++ b/src/test/auxiliary/issue-19340-1.rs
@@ -0,0 +1,13 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub enum Homura {
+    Madoka { name: String },
+}
diff --git a/src/test/run-pass/issue-19340-1.rs b/src/test/run-pass/issue-19340-1.rs
new file mode 100644
index 00000000000..b7a6391ee04
--- /dev/null
+++ b/src/test/run-pass/issue-19340-1.rs
@@ -0,0 +1,23 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:issue-19340-1.rs
+
+extern crate "issue-19340-1" as lib;
+
+use lib::Homura;
+
+fn main() {
+    let homura = Homura::Madoka { name: "Kaname".into_string() };
+
+    match homura {
+        Homura::Madoka { name } => (),
+    };
+}