diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index de7ca479b0b66..507de9a9e3673 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -534,13 +534,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { report_unexpected_def(); return tcx.types.err; } - Def::Variant(..) | Def::Struct(..) => { + Def::Variant(..) => { let variant = tcx.expect_variant_def(def); if variant.kind != VariantKind::Unit { report_unexpected_def(); return tcx.types.err; } } + 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 tcx.types.err; + } + } Def::Const(..) | Def::AssociatedConst(..) => {} // OK _ => bug!("unexpected pattern definition {:?}", def) } @@ -589,9 +597,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { report_unexpected_def(false); return tcx.types.err; } - 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() {