@@ -393,8 +393,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
393393
394394 PatKind :: TupleStruct ( ref qpath, ref subpatterns, ddpos) => {
395395 let def = self . tcx . tables ( ) . qpath_def ( qpath, pat. id ) ;
396- let pat_ty = self . tcx . tables ( ) . node_id_to_type ( pat. id ) ;
397- let adt_def = match pat_ty. sty {
396+ let adt_def = match ty. sty {
398397 ty:: TyAdt ( adt_def, _) => adt_def,
399398 _ => span_bug ! ( pat. span, "tuple struct pattern not applied to an ADT" ) ,
400399 } ;
@@ -413,8 +412,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
413412
414413 PatKind :: Struct ( ref qpath, ref fields, _) => {
415414 let def = self . tcx . tables ( ) . qpath_def ( qpath, pat. id ) ;
416- let pat_ty = self . tcx . tables ( ) . node_id_to_type ( pat. id ) ;
417- let adt_def = match pat_ty. sty {
415+ let adt_def = match ty. sty {
418416 ty:: TyAdt ( adt_def, _) => adt_def,
419417 _ => {
420418 span_bug ! (
@@ -537,11 +535,14 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
537535 {
538536 match def {
539537 Def :: Variant ( variant_id) | Def :: VariantCtor ( variant_id, ..) => {
540- let ( adt_def, substs) = match ty. sty {
541- TypeVariants :: TyAdt ( adt_def, substs) => ( adt_def, substs) ,
542- _ => bug ! ( "inappropriate type for def" ) ,
543- } ;
538+ let enum_id = self . tcx . parent_def_id ( variant_id) . unwrap ( ) ;
539+ let adt_def = self . tcx . lookup_adt_def ( enum_id) ;
544540 if adt_def. variants . len ( ) > 1 {
541+ let substs = match ty. sty {
542+ TypeVariants :: TyAdt ( _, substs) => substs,
543+ TypeVariants :: TyFnDef ( _, substs, _) => substs,
544+ _ => bug ! ( "inappropriate type for def: {:?}" , ty. sty) ,
545+ } ;
545546 PatternKind :: Variant {
546547 adt_def : adt_def,
547548 substs : substs,
@@ -568,6 +569,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
568569 pat_id : ast:: NodeId ,
569570 span : Span )
570571 -> Pattern < ' tcx > {
572+ let ty = self . tcx . tables ( ) . node_id_to_type ( id) ;
571573 let def = self . tcx . tables ( ) . qpath_def ( qpath, id) ;
572574 let kind = match def {
573575 Def :: Const ( def_id) | Def :: AssociatedConst ( def_id) => {
@@ -584,12 +586,12 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
584586 }
585587 }
586588 }
587- _ => self . lower_variant_or_leaf ( def, ty, vec ! [ ] )
589+ _ => self . lower_variant_or_leaf ( def, ty, vec ! [ ] ) ,
588590 } ;
589591
590592 Pattern {
591593 span : span,
592- ty : self . tcx . tables ( ) . node_id_to_type ( id ) ,
594+ ty : ty ,
593595 kind : Box :: new ( kind) ,
594596 }
595597 }
@@ -657,6 +659,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
657659 hir:: ExprPath ( ref qpath) => qpath,
658660 _ => bug ! ( )
659661 } ;
662+ let ty = self . tcx . tables ( ) . node_id_to_type ( callee. id ) ;
660663 let def = self . tcx . tables ( ) . qpath_def ( qpath, callee. id ) ;
661664 match def {
662665 Def :: Fn ( ..) | Def :: Method ( ..) => self . lower_lit ( expr) ,
@@ -667,7 +670,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
667670 pattern : self . lower_const_expr ( expr, pat_id, span)
668671 }
669672 } ) . collect ( ) ;
670- self . lower_variant_or_leaf ( def, subpatterns)
673+ self . lower_variant_or_leaf ( def, ty , subpatterns)
671674 }
672675 }
673676 }
@@ -702,7 +705,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
702705 } )
703706 . collect ( ) ;
704707
705- self . lower_variant_or_leaf ( def, subpatterns)
708+ self . lower_variant_or_leaf ( def, pat_ty , subpatterns)
706709 }
707710
708711 hir:: ExprArray ( ref exprs) => {
0 commit comments