Skip to content

Commit d0374d0

Browse files
petrochenkovbrson
authored andcommitted
Temporary fix for metadata decoding for struct constructors
1 parent 580cbd8 commit d0374d0

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/librustc/ty/item_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
305305
/// Returns the def-id of `def_id`'s parent in the def tree. If
306306
/// this returns `None`, then `def_id` represents a crate root or
307307
/// inlined root.
308-
fn parent_def_id(&self, def_id: DefId) -> Option<DefId> {
308+
pub fn parent_def_id(&self, def_id: DefId) -> Option<DefId> {
309309
let key = self.def_key(def_id);
310310
key.parent.map(|index| DefId { krate: def_id.krate, index: index })
311311
}

src/librustc_typeck/check/_match.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
535535
report_unexpected_def();
536536
return;
537537
}
538-
Def::Variant(..) | Def::Struct(..) => {
538+
Def::Variant(..) => {
539539
let variant = tcx.expect_variant_def(def);
540540
if variant.kind != VariantKind::Unit {
541541
report_unexpected_def();
542542
return;
543543
}
544544
}
545+
Def::Struct(ctor_did) => {
546+
let did = tcx.parent_def_id(ctor_did).expect("struct ctor has no parent");
547+
let variant = tcx.lookup_adt_def(did).struct_variant();
548+
if variant.kind != VariantKind::Unit {
549+
report_unexpected_def();
550+
return;
551+
}
552+
}
545553
Def::Const(..) | Def::AssociatedConst(..) => {} // OK
546554
_ => bug!("unexpected pattern definition {:?}", def)
547555
}
@@ -592,9 +600,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
592600
report_unexpected_def(false);
593601
return;
594602
}
595-
Def::Variant(..) | Def::Struct(..) => {
603+
Def::Variant(..) => {
596604
tcx.expect_variant_def(def)
597605
}
606+
Def::Struct(ctor_did) => {
607+
let did = tcx.parent_def_id(ctor_did).expect("struct ctor has no parent");
608+
tcx.lookup_adt_def(did).struct_variant()
609+
}
598610
_ => bug!("unexpected pattern definition {:?}", def)
599611
};
600612
if variant.kind == VariantKind::Unit && subpats.is_empty() && ddpos.is_some() {

0 commit comments

Comments
 (0)