]> git.lizzy.rs Git - rust.git/commitdiff
Fix ICE when a struct variant enum contains multiple fields
authorBarosl Lee <vcs@barosl.com>
Fri, 5 Dec 2014 14:45:46 +0000 (23:45 +0900)
committerBarosl Lee <vcs@barosl.com>
Thu, 11 Dec 2014 18:38:11 +0000 (03:38 +0900)
Fixes the second case of #19340.

src/librustc/middle/borrowck/fragments.rs
src/test/run-pass/issue-19340-2.rs [new file with mode: 0644]

index 5785972c484bbb5a55eedac6b0813db17f6688e3..056d4f9d732a67fadb9a7d8291aa74b6621ae46f 100644 (file)
@@ -346,9 +346,10 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
                                                                         Rc<LoanPath<'tcx>>)>) {
     let parent_ty = parent_lp.to_type();
 
-    let add_fragment_sibling_local = |field_name| {
+    let add_fragment_sibling_local = |field_name, variant_did| {
         add_fragment_sibling_core(
-            this, tcx, gathered_fragments, parent_lp.clone(), mc, field_name, origin_lp);
+            this, tcx, gathered_fragments, parent_lp.clone(), mc, field_name, origin_lp,
+            variant_did);
     };
 
     match (&parent_ty.sty, enum_variant_info) {
@@ -363,7 +364,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
             for i in range(0, tuple_len) {
                 if i == tuple_idx { continue }
                 let field_name = mc::PositionalField(i);
-                add_fragment_sibling_local(field_name);
+                add_fragment_sibling_local(field_name, None);
             }
         }
 
@@ -376,7 +377,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
                             continue;
                         }
                         let field_name = mc::NamedField(f.name);
-                        add_fragment_sibling_local(field_name);
+                        add_fragment_sibling_local(field_name, None);
                     }
                 }
                 mc::PositionalField(tuple_idx) => {
@@ -385,7 +386,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
                             continue
                         }
                         let field_name = mc::PositionalField(i);
-                        add_fragment_sibling_local(field_name);
+                        add_fragment_sibling_local(field_name, None);
                     }
                 }
             }
@@ -414,7 +415,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
                             continue;
                         }
                         let field_name = mc::NamedField(variant_arg_ident.name);
-                        add_fragment_sibling_local(field_name);
+                        add_fragment_sibling_local(field_name, Some(variant_info.id));
                     }
                 }
                 mc::PositionalField(tuple_idx) => {
@@ -424,7 +425,7 @@ fn add_fragment_siblings_for_extension<'tcx>(this: &MoveData<'tcx>,
                             continue;
                         }
                         let field_name = mc::PositionalField(i);
-                        add_fragment_sibling_local(field_name);
+                        add_fragment_sibling_local(field_name, None);
                     }
                 }
             }
@@ -447,10 +448,11 @@ fn add_fragment_sibling_core<'tcx>(this: &MoveData<'tcx>,
                                    parent: Rc<LoanPath<'tcx>>,
                                    mc: mc::MutabilityCategory,
                                    new_field_name: mc::FieldName,
-                                   origin_lp: &Rc<LoanPath<'tcx>>) -> MovePathIndex {
+                                   origin_lp: &Rc<LoanPath<'tcx>>,
+                                   enum_variant_did: Option<ast::DefId>) -> MovePathIndex {
     let opt_variant_did = match parent.kind {
         LpDowncast(_, variant_did) => Some(variant_did),
-        LpVar(..) | LpUpvar(..) | LpExtend(..) => None,
+        LpVar(..) | LpUpvar(..) | LpExtend(..) => enum_variant_did,
     };
 
     let loan_path_elem = LpInterior(mc::InteriorField(new_field_name));
diff --git a/src/test/run-pass/issue-19340-2.rs b/src/test/run-pass/issue-19340-2.rs
new file mode 100644 (file)
index 0000000..5179c1e
--- /dev/null
@@ -0,0 +1,30 @@
+// 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.
+
+enum Homura {
+    Madoka {
+        name: String,
+        age: u32,
+    },
+}
+
+fn main() {
+    let homura = Homura::Madoka {
+        name: "Akemi".into_string(),
+        age: 14,
+    };
+
+    match homura {
+        Homura::Madoka {
+            name,
+            age,
+        } => (),
+    };
+}