@@ -716,7 +716,7 @@ use smallvec::{smallvec, SmallVec};
716716use std:: fmt;
717717
718718use crate :: constructor:: { Constructor , ConstructorSet } ;
719- use crate :: pat:: { DeconstructedPat , WitnessPat } ;
719+ use crate :: pat:: { DeconstructedPat , PatOrWild , WitnessPat } ;
720720use crate :: { Captures , MatchArm , MatchCtxt , TypeCx } ;
721721
722722use self :: ValidityConstraint :: * ;
@@ -827,7 +827,7 @@ impl fmt::Display for ValidityConstraint {
827827#[ derivative( Clone ( bound = "" ) ) ]
828828struct PatStack < ' p , Cx : TypeCx > {
829829 // Rows of len 1 are very common, which is why `SmallVec[_; 2]` works well.
830- pats : SmallVec < [ & ' p DeconstructedPat < ' p , Cx > ; 2 ] > ,
830+ pats : SmallVec < [ PatOrWild < ' p , Cx > ; 2 ] > ,
831831 /// Sometimes we know that as far as this row is concerned, the current case is already handled
832832 /// by a different, more general, case. When the case is irrelevant for all rows this allows us
833833 /// to skip a case entirely. This is purely an optimization. See at the top for details.
@@ -836,7 +836,7 @@ struct PatStack<'p, Cx: TypeCx> {
836836
837837impl < ' p , Cx : TypeCx > PatStack < ' p , Cx > {
838838 fn from_pattern ( pat : & ' p DeconstructedPat < ' p , Cx > ) -> Self {
839- PatStack { pats : smallvec ! [ pat] , relevant : true }
839+ PatStack { pats : smallvec ! [ PatOrWild :: Pat ( pat) ] , relevant : true }
840840 }
841841
842842 fn is_empty ( & self ) -> bool {
@@ -847,14 +847,11 @@ impl<'p, Cx: TypeCx> PatStack<'p, Cx> {
847847 self . pats . len ( )
848848 }
849849
850- fn head_opt ( & self ) -> Option < & ' p DeconstructedPat < ' p , Cx > > {
851- self . pats . first ( ) . copied ( )
852- }
853- fn head ( & self ) -> & ' p DeconstructedPat < ' p , Cx > {
854- self . head_opt ( ) . unwrap ( )
850+ fn head ( & self ) -> PatOrWild < ' p , Cx > {
851+ self . pats [ 0 ]
855852 }
856853
857- fn iter ( & self ) -> impl Iterator < Item = & ' p DeconstructedPat < ' p , Cx > > + Captures < ' _ > {
854+ fn iter ( & self ) -> impl Iterator < Item = PatOrWild < ' p , Cx > > + Captures < ' _ > {
858855 self . pats . iter ( ) . copied ( )
859856 }
860857
@@ -872,14 +869,13 @@ impl<'p, Cx: TypeCx> PatStack<'p, Cx> {
872869 /// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
873870 fn pop_head_constructor (
874871 & self ,
875- pcx : & PlaceCtxt < ' _ , ' p , Cx > ,
876872 ctor : & Constructor < Cx > ,
877- ctor_sub_tys : & [ Cx :: Ty ] ,
873+ ctor_arity : usize ,
878874 ctor_is_relevant : bool ,
879875 ) -> PatStack < ' p , Cx > {
880876 // We pop the head pattern and push the new fields extracted from the arguments of
881877 // `self.head()`.
882- let mut new_pats = self . head ( ) . specialize ( pcx , ctor, ctor_sub_tys ) ;
878+ let mut new_pats = self . head ( ) . specialize ( ctor, ctor_arity ) ;
883879 new_pats. extend_from_slice ( & self . pats [ 1 ..] ) ;
884880 // `ctor` is relevant for this row if it is the actual constructor of this row, or if the
885881 // row has a wildcard and `ctor` is relevant for wildcards.
@@ -926,11 +922,11 @@ impl<'p, Cx: TypeCx> MatrixRow<'p, Cx> {
926922 self . pats . len ( )
927923 }
928924
929- fn head ( & self ) -> & ' p DeconstructedPat < ' p , Cx > {
925+ fn head ( & self ) -> PatOrWild < ' p , Cx > {
930926 self . pats . head ( )
931927 }
932928
933- fn iter ( & self ) -> impl Iterator < Item = & ' p DeconstructedPat < ' p , Cx > > + Captures < ' _ > {
929+ fn iter ( & self ) -> impl Iterator < Item = PatOrWild < ' p , Cx > > + Captures < ' _ > {
934930 self . pats . iter ( )
935931 }
936932
@@ -949,14 +945,13 @@ impl<'p, Cx: TypeCx> MatrixRow<'p, Cx> {
949945 /// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
950946 fn pop_head_constructor (
951947 & self ,
952- pcx : & PlaceCtxt < ' _ , ' p , Cx > ,
953948 ctor : & Constructor < Cx > ,
954- ctor_sub_tys : & [ Cx :: Ty ] ,
949+ ctor_arity : usize ,
955950 ctor_is_relevant : bool ,
956951 parent_row : usize ,
957952 ) -> MatrixRow < ' p , Cx > {
958953 MatrixRow {
959- pats : self . pats . pop_head_constructor ( pcx , ctor, ctor_sub_tys , ctor_is_relevant) ,
954+ pats : self . pats . pop_head_constructor ( ctor, ctor_arity , ctor_is_relevant) ,
960955 parent_row,
961956 is_under_guard : self . is_under_guard ,
962957 useful : false ,
@@ -1054,7 +1049,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10541049 }
10551050
10561051 /// Iterate over the first pattern of each row.
1057- fn heads ( & self ) -> impl Iterator < Item = & ' p DeconstructedPat < ' p , Cx > > + Clone + Captures < ' _ > {
1052+ fn heads ( & self ) -> impl Iterator < Item = PatOrWild < ' p , Cx > > + Clone + Captures < ' _ > {
10581053 self . rows ( ) . map ( |r| r. head ( ) )
10591054 }
10601055
@@ -1066,11 +1061,12 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10661061 ctor_is_relevant : bool ,
10671062 ) -> Matrix < ' p , Cx > {
10681063 let ctor_sub_tys = pcx. ctor_sub_tys ( ctor) ;
1064+ let arity = ctor_sub_tys. len ( ) ;
10691065 let specialized_place_ty =
10701066 ctor_sub_tys. iter ( ) . chain ( self . place_ty [ 1 ..] . iter ( ) ) . copied ( ) . collect ( ) ;
10711067 let ctor_sub_validity = self . place_validity [ 0 ] . specialize ( ctor) ;
10721068 let specialized_place_validity = std:: iter:: repeat ( ctor_sub_validity)
1073- . take ( ctor . arity ( pcx ) )
1069+ . take ( arity)
10741070 . chain ( self . place_validity [ 1 ..] . iter ( ) . copied ( ) )
10751071 . collect ( ) ;
10761072 let mut matrix = Matrix {
@@ -1081,8 +1077,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
10811077 } ;
10821078 for ( i, row) in self . rows ( ) . enumerate ( ) {
10831079 if ctor. is_covered_by ( pcx, row. head ( ) . ctor ( ) ) {
1084- let new_row =
1085- row. pop_head_constructor ( pcx, ctor, ctor_sub_tys, ctor_is_relevant, i) ;
1080+ let new_row = row. pop_head_constructor ( ctor, arity, ctor_is_relevant, i) ;
10861081 matrix. expand_and_push ( new_row) ;
10871082 }
10881083 }
0 commit comments