about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2016-09-15 00:51:46 +0300
committerBrian Anderson <banderson@mozilla.com>2016-10-18 22:51:00 +0000
commitd0374d0475150281359debe1355c10e1d0e51cfa (patch)
treedd6c4a338cc8bd475d6adbde327061662d733487
parent580cbd889f4a9e2baae3efda8589c6721da3f0f2 (diff)
downloadrust-d0374d0475150281359debe1355c10e1d0e51cfa.tar.gz
rust-d0374d0475150281359debe1355c10e1d0e51cfa.zip
Temporary fix for metadata decoding for struct constructors
-rw-r--r--src/librustc/ty/item_path.rs2
-rw-r--r--src/librustc_typeck/check/_match.rs16
2 files changed, 15 insertions, 3 deletions
diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs
index 8ddd8bef36a..5e4e7b342d6 100644
--- a/src/librustc/ty/item_path.rs
+++ b/src/librustc/ty/item_path.rs
@@ -305,7 +305,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
     /// Returns the def-id of `def_id`'s parent in the def tree. If
     /// this returns `None`, then `def_id` represents a crate root or
     /// inlined root.
-    fn parent_def_id(&self, def_id: DefId) -> Option<DefId> {
+    pub fn parent_def_id(&self, def_id: DefId) -> Option<DefId> {
         let key = self.def_key(def_id);
         key.parent.map(|index| DefId { krate: def_id.krate, index: index })
     }
diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs
index 04f22b19511..c2fba803857 100644
--- a/src/librustc_typeck/check/_match.rs
+++ b/src/librustc_typeck/check/_match.rs
@@ -535,13 +535,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
                 report_unexpected_def();
                 return;
             }
-            Def::Variant(..) | Def::Struct(..) => {
+            Def::Variant(..) => {
                 let variant = tcx.expect_variant_def(def);
                 if variant.kind != VariantKind::Unit {
                     report_unexpected_def();
                     return;
                 }
             }
+            Def::Struct(ctor_did) => {
+                let did = tcx.parent_def_id(ctor_did).expect("struct ctor has no parent");
+                let variant = tcx.lookup_adt_def(did).struct_variant();
+                if variant.kind != VariantKind::Unit {
+                    report_unexpected_def();
+                    return;
+                }
+            }
             Def::Const(..) | Def::AssociatedConst(..) => {} // OK
             _ => bug!("unexpected pattern definition {:?}", def)
         }
@@ -592,9 +600,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
                 report_unexpected_def(false);
                 return;
             }
-            Def::Variant(..) | Def::Struct(..) => {
+            Def::Variant(..) => {
                 tcx.expect_variant_def(def)
             }
+            Def::Struct(ctor_did) => {
+                let did = tcx.parent_def_id(ctor_did).expect("struct ctor has no parent");
+                tcx.lookup_adt_def(did).struct_variant()
+            }
             _ => bug!("unexpected pattern definition {:?}", def)
         };
         if variant.kind == VariantKind::Unit && subpats.is_empty() && ddpos.is_some() {