@@ -56,9 +56,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
56
56
( ( prefix. len ( ) + suffix. len ( ) ) . try_into ( ) . unwrap ( ) , false )
57
57
} ;
58
58
59
- let mut prefix_opt = false ;
60
-
61
- if self . is_constant_pattern_subslice ( prefix) && opt_slice. is_none ( ) && suffix. len ( ) == 0 {
59
+ if self . subslice_work_optimizing ( prefix) {
62
60
let elem_ty = prefix[ 0 ] . ty ;
63
61
let prefix_valtree = self . simplify_const_pattern_slice_into_valtree ( prefix) ;
64
62
@@ -72,10 +70,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
72
70
) ;
73
71
74
72
match_pairs. push ( match_pair) ;
75
- prefix_opt = true ;
76
- }
77
-
78
- if !prefix_opt {
73
+ } else {
79
74
match_pairs. extend ( prefix. iter ( ) . enumerate ( ) . map ( |( idx, subpattern) | {
80
75
let elem = ProjectionElem :: ConstantIndex {
81
76
offset : idx as u64 ,
@@ -108,17 +103,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
108
103
} ) ) ;
109
104
}
110
105
111
- fn is_constant_pattern_subslice ( & self , subslice : & [ Box < Pat < ' tcx > > ] ) -> bool {
112
- subslice . len ( ) > 1 && subslice. iter ( ) . all ( |p| self . is_constant_pattern ( p) )
106
+ fn subslice_work_optimizing ( & self , subslice : & [ Box < Pat < ' tcx > > ] ) -> bool {
107
+ slice . len ( ) > 1 && subslice. iter ( ) . all ( |p| self . is_constant_pattern ( p) )
113
108
}
114
109
115
110
fn is_constant_pattern ( & self , pat : & Pat < ' tcx > ) -> bool {
116
111
if let PatKind :: Constant { value } = pat. kind
117
112
&& let Const :: Ty ( _, const_) = value
118
113
&& let ty:: ConstKind :: Value ( ty, valtree) = const_. kind ( )
119
- && let ty:: ValTree :: Leaf ( scalar ) = valtree
114
+ && let ty:: ValTree :: Leaf ( _ ) = valtree
120
115
&& self . tcx . types . u8 == ty
121
- && scalar. to_u8 ( ) != b'_'
122
116
{
123
117
true
124
118
} else {
0 commit comments