@@ -582,8 +582,8 @@ enum Constructor<'tcx> {
582
582
// Meta-constructors
583
583
/// Ranges of literal values (`2..=5` and `2..5`).
584
584
ConstantRange ( u128 , u128 , Ty < ' tcx > , RangeEnd ) ,
585
- /// Slice patterns. Captures any array constructor of length >= n .
586
- VarLenSlice ( u64 ) ,
585
+ /// Slice patterns. Captures any array constructor of length >= i+j .
586
+ VarLenSlice ( u64 , u64 ) ,
587
587
/// Wildcard metaconstructor.
588
588
Wildcard ,
589
589
/// List of constructors that were _not_ present in the first column
@@ -739,7 +739,9 @@ impl<'tcx> Constructor<'tcx> {
739
739
. collect ( )
740
740
}
741
741
ConstantRange ( ..) => smallvec ! [ self ] ,
742
- VarLenSlice ( len) => ( * len..pcx. max_slice_length + 1 ) . map ( FixedLenSlice ) . collect ( ) ,
742
+ VarLenSlice ( prefix, suffix) => {
743
+ ( prefix + suffix..pcx. max_slice_length + 1 ) . map ( FixedLenSlice ) . collect ( )
744
+ }
743
745
Wildcard => {
744
746
let is_declared_nonexhaustive =
745
747
!cx. is_local ( pcx. ty ) && cx. is_non_exhaustive_enum ( pcx. ty ) ;
@@ -852,20 +854,21 @@ impl<'tcx> Constructor<'tcx> {
852
854
FixedLenSlice ( self_len) => {
853
855
let overlaps = |c : & Constructor < ' _ > | match c {
854
856
FixedLenSlice ( other_len) => * other_len == self_len,
855
- VarLenSlice ( other_len ) => * other_len <= self_len,
857
+ VarLenSlice ( prefix , suffix ) => prefix + suffix <= self_len,
856
858
_ => false ,
857
859
} ;
858
860
if used_ctors. iter ( ) . any ( overlaps) { smallvec ! [ ] } else { smallvec ! [ self ] }
859
861
}
860
- VarLenSlice ( self_len) => {
862
+ VarLenSlice ( self_prefix, self_suffix) => {
863
+ let self_len = self_prefix + self_suffix;
861
864
// Initially we cover all slice lengths starting from self_len.
862
865
863
866
// If there is a VarLenSlice(n) in used_ctors, then we have to discard
864
867
// all lengths >= n. So we pick the smallest one.
865
868
let max_len: Option < _ > = used_ctors
866
869
. iter ( )
867
870
. filter_map ( |c : & Constructor < ' tcx > | match c {
868
- VarLenSlice ( other_len ) => Some ( * other_len ) ,
871
+ VarLenSlice ( prefix , suffix ) => Some ( prefix + suffix ) ,
869
872
_ => None ,
870
873
} )
871
874
. min ( ) ;
@@ -926,7 +929,7 @@ impl<'tcx> Constructor<'tcx> {
926
929
Start => self_len,
927
930
Boundary ( n) => n + 1 ,
928
931
} ;
929
- remaining_ctors. push ( VarLenSlice ( final_length) ) ;
932
+ remaining_ctors. push ( VarLenSlice ( final_length, 0 ) ) ;
930
933
}
931
934
932
935
remaining_ctors
@@ -970,7 +973,7 @@ impl<'tcx> Constructor<'tcx> {
970
973
ty : Ty < ' tcx > ,
971
974
) -> impl Iterator < Item = Pat < ' tcx > > + DoubleEndedIterator {
972
975
debug ! ( "wildcard_subpatterns({:#?}, {:?})" , self , ty) ;
973
- let subpattern_types = match self {
976
+ let subpattern_types = match * self {
974
977
Single | Variant ( _) => match ty. kind {
975
978
ty:: Tuple ( ref fs) => fs. into_iter ( ) . map ( |t| t. expect_ty ( ) ) . collect ( ) ,
976
979
ty:: Ref ( _, rty, _) => vec ! [ rty] ,
@@ -1015,8 +1018,12 @@ impl<'tcx> Constructor<'tcx> {
1015
1018
ty:: Slice ( ty) | ty:: Array ( ty, _) => bug ! ( "bad slice pattern {:?} {:?}" , self , ty) ,
1016
1019
_ => vec ! [ ] ,
1017
1020
} ,
1018
- FixedLenSlice ( length) | VarLenSlice ( length) => match ty. kind {
1019
- ty:: Slice ( ty) | ty:: Array ( ty, _) => ( 0 ..* length) . map ( |_| ty) . collect ( ) ,
1021
+ FixedLenSlice ( length) => match ty. kind {
1022
+ ty:: Slice ( ty) | ty:: Array ( ty, _) => ( 0 ..length) . map ( |_| ty) . collect ( ) ,
1023
+ _ => bug ! ( "bad slice pattern {:?} {:?}" , self , ty) ,
1024
+ } ,
1025
+ VarLenSlice ( prefix, suffix) => match ty. kind {
1026
+ ty:: Slice ( ty) | ty:: Array ( ty, _) => ( 0 ..prefix + suffix) . map ( |_| ty) . collect ( ) ,
1020
1027
_ => bug ! ( "bad slice pattern {:?} {:?}" , self , ty) ,
1021
1028
} ,
1022
1029
ConstantValue ( _) | MissingConstructors ( _) | ConstantRange ( ..) | Wildcard => vec ! [ ] ,
@@ -1032,7 +1039,7 @@ impl<'tcx> Constructor<'tcx> {
1032
1039
/// A struct pattern's arity is the number of fields it contains, etc.
1033
1040
fn arity < ' a > ( & self , cx : & MatchCheckCtxt < ' a , ' tcx > , ty : Ty < ' tcx > ) -> u64 {
1034
1041
debug ! ( "Constructor::arity({:#?}, {:?})" , self , ty) ;
1035
- match self {
1042
+ match * self {
1036
1043
Single | Variant ( _) => match ty. kind {
1037
1044
ty:: Tuple ( ref fs) => fs. len ( ) as u64 ,
1038
1045
ty:: Ref ( ..) => 1 ,
@@ -1042,7 +1049,8 @@ impl<'tcx> Constructor<'tcx> {
1042
1049
ty:: Slice ( ..) | ty:: Array ( ..) => bug ! ( "bad slice pattern {:?} {:?}" , self , ty) ,
1043
1050
_ => 0 ,
1044
1051
} ,
1045
- FixedLenSlice ( length) | VarLenSlice ( length) => * length,
1052
+ FixedLenSlice ( length) => length,
1053
+ VarLenSlice ( prefix, suffix) => prefix + suffix,
1046
1054
ConstantValue ( _) | ConstantRange ( ..) | Wildcard | MissingConstructors ( _) => 0 ,
1047
1055
}
1048
1056
}
@@ -1095,7 +1103,7 @@ impl<'tcx> Constructor<'tcx> {
1095
1103
FixedLenSlice ( _) => {
1096
1104
PatKind :: Slice { prefix : pats. collect ( ) , slice : None , suffix : vec ! [ ] }
1097
1105
}
1098
- VarLenSlice ( _) => match ty. kind {
1106
+ VarLenSlice ( _, _ ) => match ty. kind {
1099
1107
ty:: Slice ( ty) | ty:: Array ( ty, _) => {
1100
1108
let prefix = pats. collect ( ) ;
1101
1109
if cx. tcx . features ( ) . slice_patterns {
@@ -1303,7 +1311,7 @@ fn all_constructors<'a, 'tcx>(
1303
1311
if cx. is_uninhabited ( sub_ty) {
1304
1312
vec ! [ FixedLenSlice ( 0 ) ]
1305
1313
} else {
1306
- vec ! [ VarLenSlice ( 0 ) ]
1314
+ vec ! [ VarLenSlice ( 0 , 0 ) ]
1307
1315
}
1308
1316
}
1309
1317
ty:: Adt ( def, substs) if def. is_enum ( ) => def
@@ -1866,11 +1874,12 @@ fn pat_constructors<'tcx>(
1866
1874
_ => span_bug ! ( pat. span, "bad ty {:?} for array pattern" , pcx. ty) ,
1867
1875
} ,
1868
1876
PatKind :: Slice { ref prefix, ref slice, ref suffix } => {
1869
- let pat_len = prefix. len ( ) as u64 + suffix. len ( ) as u64 ;
1877
+ let prefix = prefix. len ( ) as u64 ;
1878
+ let suffix = suffix. len ( ) as u64 ;
1870
1879
if slice. is_some ( ) {
1871
- smallvec ! [ VarLenSlice ( pat_len ) ]
1880
+ smallvec ! [ VarLenSlice ( prefix , suffix ) ]
1872
1881
} else {
1873
- smallvec ! [ FixedLenSlice ( pat_len ) ]
1882
+ smallvec ! [ FixedLenSlice ( prefix + suffix ) ]
1874
1883
}
1875
1884
}
1876
1885
PatKind :: Or { .. } => {
0 commit comments