@@ -393,8 +393,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
393
393
394
394
PatKind :: TupleStruct ( ref qpath, ref subpatterns, ddpos) => {
395
395
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 {
398
397
ty:: TyAdt ( adt_def, _) => adt_def,
399
398
_ => span_bug ! ( pat. span, "tuple struct pattern not applied to an ADT" ) ,
400
399
} ;
@@ -413,8 +412,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
413
412
414
413
PatKind :: Struct ( ref qpath, ref fields, _) => {
415
414
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 {
418
416
ty:: TyAdt ( adt_def, _) => adt_def,
419
417
_ => {
420
418
span_bug ! (
@@ -537,11 +535,14 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
537
535
{
538
536
match def {
539
537
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) ;
544
540
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
+ } ;
545
546
PatternKind :: Variant {
546
547
adt_def : adt_def,
547
548
substs : substs,
@@ -568,6 +569,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
568
569
pat_id : ast:: NodeId ,
569
570
span : Span )
570
571
-> Pattern < ' tcx > {
572
+ let ty = self . tcx . tables ( ) . node_id_to_type ( id) ;
571
573
let def = self . tcx . tables ( ) . qpath_def ( qpath, id) ;
572
574
let kind = match def {
573
575
Def :: Const ( def_id) | Def :: AssociatedConst ( def_id) => {
@@ -584,12 +586,12 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
584
586
}
585
587
}
586
588
}
587
- _ => self . lower_variant_or_leaf ( def, ty, vec ! [ ] )
589
+ _ => self . lower_variant_or_leaf ( def, ty, vec ! [ ] ) ,
588
590
} ;
589
591
590
592
Pattern {
591
593
span : span,
592
- ty : self . tcx . tables ( ) . node_id_to_type ( id ) ,
594
+ ty : ty ,
593
595
kind : Box :: new ( kind) ,
594
596
}
595
597
}
@@ -657,6 +659,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
657
659
hir:: ExprPath ( ref qpath) => qpath,
658
660
_ => bug ! ( )
659
661
} ;
662
+ let ty = self . tcx . tables ( ) . node_id_to_type ( callee. id ) ;
660
663
let def = self . tcx . tables ( ) . qpath_def ( qpath, callee. id ) ;
661
664
match def {
662
665
Def :: Fn ( ..) | Def :: Method ( ..) => self . lower_lit ( expr) ,
@@ -667,7 +670,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
667
670
pattern : self . lower_const_expr ( expr, pat_id, span)
668
671
}
669
672
} ) . collect ( ) ;
670
- self . lower_variant_or_leaf ( def, subpatterns)
673
+ self . lower_variant_or_leaf ( def, ty , subpatterns)
671
674
}
672
675
}
673
676
}
@@ -702,7 +705,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
702
705
} )
703
706
. collect ( ) ;
704
707
705
- self . lower_variant_or_leaf ( def, subpatterns)
708
+ self . lower_variant_or_leaf ( def, pat_ty , subpatterns)
706
709
}
707
710
708
711
hir:: ExprArray ( ref exprs) => {
0 commit comments