@@ -838,31 +838,24 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
838838 // of type `Box` is to use a `box` pattern via #[feature(box_patterns)].
839839 PatKind :: Box { subpattern : hoist ( & pat. fields [ 0 ] ) }
840840 }
841- Struct | Variant ( _) | UnionField => match pat. ty ( ) . kind ( ) {
842- ty:: Tuple ( ..) => PatKind :: StructLike {
843- enum_info : EnumInfo :: NotEnum ,
844- subpatterns : subpatterns
845- . enumerate ( )
846- . map ( |( i, pattern) | FieldPat { field : FieldIdx :: new ( i) , pattern } )
847- . collect ( ) ,
848- } ,
849- & ty:: Adt ( adt_def, _) => {
850- let variant_index = RustcPatCtxt :: variant_index_for_adt ( & pat. ctor ( ) , adt_def) ;
851- let subpatterns = subpatterns
852- . enumerate ( )
853- . map ( |( i, pattern) | FieldPat { field : FieldIdx :: new ( i) , pattern } )
854- . collect ( ) ;
841+ Struct | Variant ( _) | UnionField => {
842+ let enum_info = match * pat. ty ( ) . kind ( ) {
843+ ty:: Adt ( adt_def, _) if adt_def. is_enum ( ) => EnumInfo :: Enum {
844+ adt_def,
845+ variant_index : RustcPatCtxt :: variant_index_for_adt ( pat. ctor ( ) , adt_def) ,
846+ } ,
847+ ty:: Adt ( ..) | ty:: Tuple ( ..) => EnumInfo :: NotEnum ,
848+ _ => bug ! ( "unexpected ctor for type {:?} {:?}" , pat. ctor( ) , * pat. ty( ) ) ,
849+ } ;
855850
856- let enum_info = if adt_def . is_enum ( ) {
857- EnumInfo :: Enum { adt_def , variant_index }
858- } else {
859- EnumInfo :: NotEnum
860- } ;
851+ let subpatterns = pat
852+ . iter_fields ( )
853+ . enumerate ( )
854+ . map ( | ( i , pat ) | FieldPat { field : FieldIdx :: new ( i ) , pattern : hoist ( pat ) } )
855+ . collect :: < Vec < _ > > ( ) ;
861856
862- PatKind :: StructLike { enum_info, subpatterns }
863- }
864- _ => bug ! ( "unexpected ctor for type {:?} {:?}" , pat. ctor( ) , * pat. ty( ) ) ,
865- } ,
857+ PatKind :: StructLike { enum_info, subpatterns }
858+ }
866859 // Note: given the expansion of `&str` patterns done in `expand_pattern`, we should
867860 // be careful to reconstruct the correct constant pattern here. However a string
868861 // literal pattern will never be reported as a non-exhaustiveness witness, so we
0 commit comments