@@ -716,7 +716,7 @@ use smallvec::{smallvec, SmallVec};
716
716
use std:: fmt;
717
717
718
718
use crate :: constructor:: { Constructor , ConstructorSet } ;
719
- use crate :: pat:: { DeconstructedPat , WitnessPat } ;
719
+ use crate :: pat:: { DeconstructedPat , PatOrWild , WitnessPat } ;
720
720
use crate :: { Captures , MatchArm , MatchCtxt , TypeCx } ;
721
721
722
722
use self :: ValidityConstraint :: * ;
@@ -827,7 +827,7 @@ impl fmt::Display for ValidityConstraint {
827
827
#[ derivative( Clone ( bound = "" ) ) ]
828
828
struct PatStack < ' p , Cx : TypeCx > {
829
829
// 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 ] > ,
831
831
/// Sometimes we know that as far as this row is concerned, the current case is already handled
832
832
/// by a different, more general, case. When the case is irrelevant for all rows this allows us
833
833
/// 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> {
836
836
837
837
impl < ' p , Cx : TypeCx > PatStack < ' p , Cx > {
838
838
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 }
840
840
}
841
841
842
842
fn is_empty ( & self ) -> bool {
@@ -847,14 +847,11 @@ impl<'p, Cx: TypeCx> PatStack<'p, Cx> {
847
847
self . pats . len ( )
848
848
}
849
849
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 ]
855
852
}
856
853
857
- fn iter ( & self ) -> impl Iterator < Item = & ' p DeconstructedPat < ' p , Cx > > + Captures < ' _ > {
854
+ fn iter ( & self ) -> impl Iterator < Item = PatOrWild < ' p , Cx > > + Captures < ' _ > {
858
855
self . pats . iter ( ) . copied ( )
859
856
}
860
857
@@ -872,14 +869,13 @@ impl<'p, Cx: TypeCx> PatStack<'p, Cx> {
872
869
/// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
873
870
fn pop_head_constructor (
874
871
& self ,
875
- pcx : & PlaceCtxt < ' _ , ' p , Cx > ,
876
872
ctor : & Constructor < Cx > ,
877
- ctor_sub_tys : & [ Cx :: Ty ] ,
873
+ ctor_arity : usize ,
878
874
ctor_is_relevant : bool ,
879
875
) -> PatStack < ' p , Cx > {
880
876
// We pop the head pattern and push the new fields extracted from the arguments of
881
877
// `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 ) ;
883
879
new_pats. extend_from_slice ( & self . pats [ 1 ..] ) ;
884
880
// `ctor` is relevant for this row if it is the actual constructor of this row, or if the
885
881
// row has a wildcard and `ctor` is relevant for wildcards.
@@ -926,11 +922,11 @@ impl<'p, Cx: TypeCx> MatrixRow<'p, Cx> {
926
922
self . pats . len ( )
927
923
}
928
924
929
- fn head ( & self ) -> & ' p DeconstructedPat < ' p , Cx > {
925
+ fn head ( & self ) -> PatOrWild < ' p , Cx > {
930
926
self . pats . head ( )
931
927
}
932
928
933
- fn iter ( & self ) -> impl Iterator < Item = & ' p DeconstructedPat < ' p , Cx > > + Captures < ' _ > {
929
+ fn iter ( & self ) -> impl Iterator < Item = PatOrWild < ' p , Cx > > + Captures < ' _ > {
934
930
self . pats . iter ( )
935
931
}
936
932
@@ -949,14 +945,13 @@ impl<'p, Cx: TypeCx> MatrixRow<'p, Cx> {
949
945
/// Only call if `ctor.is_covered_by(self.head().ctor())` is true.
950
946
fn pop_head_constructor (
951
947
& self ,
952
- pcx : & PlaceCtxt < ' _ , ' p , Cx > ,
953
948
ctor : & Constructor < Cx > ,
954
- ctor_sub_tys : & [ Cx :: Ty ] ,
949
+ ctor_arity : usize ,
955
950
ctor_is_relevant : bool ,
956
951
parent_row : usize ,
957
952
) -> MatrixRow < ' p , Cx > {
958
953
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) ,
960
955
parent_row,
961
956
is_under_guard : self . is_under_guard ,
962
957
useful : false ,
@@ -1054,7 +1049,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
1054
1049
}
1055
1050
1056
1051
/// 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 < ' _ > {
1058
1053
self . rows ( ) . map ( |r| r. head ( ) )
1059
1054
}
1060
1055
@@ -1066,11 +1061,12 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
1066
1061
ctor_is_relevant : bool ,
1067
1062
) -> Matrix < ' p , Cx > {
1068
1063
let ctor_sub_tys = pcx. ctor_sub_tys ( ctor) ;
1064
+ let arity = ctor_sub_tys. len ( ) ;
1069
1065
let specialized_place_ty =
1070
1066
ctor_sub_tys. iter ( ) . chain ( self . place_ty [ 1 ..] . iter ( ) ) . copied ( ) . collect ( ) ;
1071
1067
let ctor_sub_validity = self . place_validity [ 0 ] . specialize ( ctor) ;
1072
1068
let specialized_place_validity = std:: iter:: repeat ( ctor_sub_validity)
1073
- . take ( ctor . arity ( pcx ) )
1069
+ . take ( arity)
1074
1070
. chain ( self . place_validity [ 1 ..] . iter ( ) . copied ( ) )
1075
1071
. collect ( ) ;
1076
1072
let mut matrix = Matrix {
@@ -1081,8 +1077,7 @@ impl<'p, Cx: TypeCx> Matrix<'p, Cx> {
1081
1077
} ;
1082
1078
for ( i, row) in self . rows ( ) . enumerate ( ) {
1083
1079
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) ;
1086
1081
matrix. expand_and_push ( new_row) ;
1087
1082
}
1088
1083
}
0 commit comments