@@ -347,6 +347,7 @@ impl PatternFolder<'tcx> for LiteralExpander<'tcx> {
347
347
) => bug ! ( "cannot deref {:#?}, {} -> {}" , val, crty, rty) ,
348
348
349
349
( _, & PatKind :: Binding { subpattern : Some ( ref s) , .. } ) => s. fold_with ( self ) ,
350
+ ( _, & PatKind :: AscribeUserType { subpattern : ref s, .. } ) => s. fold_with ( self ) ,
350
351
_ => pat. super_fold_with ( self ) ,
351
352
}
352
353
}
@@ -747,7 +748,7 @@ impl<'tcx> Constructor<'tcx> {
747
748
. iter ( )
748
749
. filter_map ( |c : & Constructor < ' _ > | match c {
749
750
Slice ( slice) => Some ( * slice) ,
750
- // FIXME(#65413 ): We ignore `ConstantValue`s here.
751
+ // FIXME(oli-obk ): implement `deref` for `ConstValue`
751
752
ConstantValue ( ..) => None ,
752
753
_ => bug ! ( "bad slice pattern constructor {:?}" , c) ,
753
754
} )
@@ -1759,9 +1760,7 @@ fn pat_constructor<'tcx>(
1759
1760
pat : & Pat < ' tcx > ,
1760
1761
) -> Option < Constructor < ' tcx > > {
1761
1762
match * pat. kind {
1762
- PatKind :: AscribeUserType { ref subpattern, .. } => {
1763
- pat_constructor ( tcx, param_env, subpattern)
1764
- }
1763
+ PatKind :: AscribeUserType { .. } => bug ! ( ) , // Handled by `expand_pattern`
1765
1764
PatKind :: Binding { .. } | PatKind :: Wild => None ,
1766
1765
PatKind :: Leaf { .. } | PatKind :: Deref { .. } => Some ( Single ) ,
1767
1766
PatKind :: Variant { adt_def, variant_index, .. } => {
@@ -1771,7 +1770,19 @@ fn pat_constructor<'tcx>(
1771
1770
if let Some ( int_range) = IntRange :: from_const ( tcx, param_env, value, pat. span ) {
1772
1771
Some ( IntRange ( int_range) )
1773
1772
} else {
1774
- Some ( ConstantValue ( value) )
1773
+ match ( value. val , & value. ty . kind ) {
1774
+ ( _, ty:: Array ( _, n) ) => {
1775
+ let len = n. eval_usize ( tcx, param_env) ;
1776
+ Some ( Slice ( Slice { array_len : Some ( len) , kind : FixedLen ( len) } ) )
1777
+ }
1778
+ ( ty:: ConstKind :: Value ( ConstValue :: Slice { start, end, .. } ) , ty:: Slice ( _) ) => {
1779
+ let len = ( end - start) as u64 ;
1780
+ Some ( Slice ( Slice { array_len : None , kind : FixedLen ( len) } ) )
1781
+ }
1782
+ // FIXME(oli-obk): implement `deref` for `ConstValue`
1783
+ // (ty::ConstKind::Value(ConstValue::ByRef { .. }), ty::Slice(_)) => { ... }
1784
+ _ => Some ( ConstantValue ( value) ) ,
1785
+ }
1775
1786
}
1776
1787
}
1777
1788
PatKind :: Range ( PatRange { lo, hi, end } ) => {
@@ -2085,32 +2096,19 @@ fn split_grouped_constructors<'p, 'tcx>(
2085
2096
let mut max_suffix_len = self_suffix;
2086
2097
let mut max_fixed_len = 0 ;
2087
2098
2088
- for row in matrix. heads ( ) {
2089
- match * row. kind {
2090
- PatKind :: Constant { value } => {
2091
- // extract the length of an array/slice from a constant
2092
- match ( value. val , & value. ty . kind ) {
2093
- ( _, ty:: Array ( _, n) ) => {
2094
- max_fixed_len =
2095
- cmp:: max ( max_fixed_len, n. eval_usize ( tcx, param_env) )
2096
- }
2097
- (
2098
- ty:: ConstKind :: Value ( ConstValue :: Slice { start, end, .. } ) ,
2099
- ty:: Slice ( _) ,
2100
- ) => max_fixed_len = cmp:: max ( max_fixed_len, ( end - start) as u64 ) ,
2101
- _ => { }
2099
+ let head_ctors =
2100
+ matrix. heads ( ) . filter_map ( |pat| pat_constructor ( tcx, param_env, pat) ) ;
2101
+ for ctor in head_ctors {
2102
+ match ctor {
2103
+ Slice ( slice) => match slice. pattern_kind ( ) {
2104
+ FixedLen ( len) => {
2105
+ max_fixed_len = cmp:: max ( max_fixed_len, len) ;
2102
2106
}
2103
- }
2104
- PatKind :: Slice { ref prefix, slice : None , ref suffix }
2105
- | PatKind :: Array { ref prefix, slice : None , ref suffix } => {
2106
- let fixed_len = prefix. len ( ) as u64 + suffix. len ( ) as u64 ;
2107
- max_fixed_len = cmp:: max ( max_fixed_len, fixed_len) ;
2108
- }
2109
- PatKind :: Slice { ref prefix, slice : Some ( _) , ref suffix }
2110
- | PatKind :: Array { ref prefix, slice : Some ( _) , ref suffix } => {
2111
- max_prefix_len = cmp:: max ( max_prefix_len, prefix. len ( ) as u64 ) ;
2112
- max_suffix_len = cmp:: max ( max_suffix_len, suffix. len ( ) as u64 ) ;
2113
- }
2107
+ VarLen ( prefix, suffix) => {
2108
+ max_prefix_len = cmp:: max ( max_prefix_len, prefix) ;
2109
+ max_suffix_len = cmp:: max ( max_suffix_len, suffix) ;
2110
+ }
2111
+ } ,
2114
2112
_ => { }
2115
2113
}
2116
2114
}
@@ -2250,21 +2248,17 @@ fn patterns_for_variant<'p, 'a: 'p, 'tcx>(
2250
2248
/// fields filled with wild patterns.
2251
2249
fn specialize_one_pattern < ' p , ' a : ' p , ' q : ' p , ' tcx > (
2252
2250
cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
2253
- mut pat : & ' q Pat < ' tcx > ,
2251
+ pat : & ' q Pat < ' tcx > ,
2254
2252
constructor : & Constructor < ' tcx > ,
2255
2253
ctor_wild_subpatterns : & [ & ' p Pat < ' tcx > ] ,
2256
2254
) -> Option < PatStack < ' p , ' tcx > > {
2257
- while let PatKind :: AscribeUserType { ref subpattern, .. } = * pat. kind {
2258
- pat = subpattern;
2259
- }
2260
-
2261
2255
if let NonExhaustive = constructor {
2262
2256
// Only a wildcard pattern can match the special extra constructor
2263
2257
return if pat. is_wildcard ( ) { Some ( PatStack :: default ( ) ) } else { None } ;
2264
2258
}
2265
2259
2266
2260
let result = match * pat. kind {
2267
- PatKind :: AscribeUserType { .. } => bug ! ( ) , // Handled above
2261
+ PatKind :: AscribeUserType { .. } => bug ! ( ) , // Handled by `expand_pattern`
2268
2262
2269
2263
PatKind :: Binding { .. } | PatKind :: Wild => {
2270
2264
Some ( PatStack :: from_slice ( ctor_wild_subpatterns) )
0 commit comments