@@ -347,6 +347,7 @@ impl PatternFolder<'tcx> for LiteralExpander<'tcx> {
347347 ) => bug ! ( "cannot deref {:#?}, {} -> {}" , val, crty, rty) ,
348348
349349 ( _, & PatKind :: Binding { subpattern : Some ( ref s) , .. } ) => s. fold_with ( self ) ,
350+ ( _, & PatKind :: AscribeUserType { subpattern : ref s, .. } ) => s. fold_with ( self ) ,
350351 _ => pat. super_fold_with ( self ) ,
351352 }
352353 }
@@ -747,7 +748,7 @@ impl<'tcx> Constructor<'tcx> {
747748 . iter ( )
748749 . filter_map ( |c : & Constructor < ' _ > | match c {
749750 Slice ( slice) => Some ( * slice) ,
750- // FIXME(#65413 ): We ignore `ConstantValue`s here.
751+ // FIXME(oli-obk ): implement `deref` for `ConstValue`
751752 ConstantValue ( ..) => None ,
752753 _ => bug ! ( "bad slice pattern constructor {:?}" , c) ,
753754 } )
@@ -1759,9 +1760,7 @@ fn pat_constructor<'tcx>(
17591760 pat : & Pat < ' tcx > ,
17601761) -> Option < Constructor < ' tcx > > {
17611762 match * pat. kind {
1762- PatKind :: AscribeUserType { ref subpattern, .. } => {
1763- pat_constructor ( tcx, param_env, subpattern)
1764- }
1763+ PatKind :: AscribeUserType { .. } => bug ! ( ) , // Handled by `expand_pattern`
17651764 PatKind :: Binding { .. } | PatKind :: Wild => None ,
17661765 PatKind :: Leaf { .. } | PatKind :: Deref { .. } => Some ( Single ) ,
17671766 PatKind :: Variant { adt_def, variant_index, .. } => {
@@ -1771,7 +1770,19 @@ fn pat_constructor<'tcx>(
17711770 if let Some ( int_range) = IntRange :: from_const ( tcx, param_env, value, pat. span ) {
17721771 Some ( IntRange ( int_range) )
17731772 } 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+ }
17751786 }
17761787 }
17771788 PatKind :: Range ( PatRange { lo, hi, end } ) => {
@@ -2085,32 +2096,19 @@ fn split_grouped_constructors<'p, 'tcx>(
20852096 let mut max_suffix_len = self_suffix;
20862097 let mut max_fixed_len = 0 ;
20872098
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) ;
21022106 }
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+ } ,
21142112 _ => { }
21152113 }
21162114 }
@@ -2250,21 +2248,17 @@ fn patterns_for_variant<'p, 'a: 'p, 'tcx>(
22502248/// fields filled with wild patterns.
22512249fn specialize_one_pattern < ' p , ' a : ' p , ' q : ' p , ' tcx > (
22522250 cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
2253- mut pat : & ' q Pat < ' tcx > ,
2251+ pat : & ' q Pat < ' tcx > ,
22542252 constructor : & Constructor < ' tcx > ,
22552253 ctor_wild_subpatterns : & [ & ' p Pat < ' tcx > ] ,
22562254) -> Option < PatStack < ' p , ' tcx > > {
2257- while let PatKind :: AscribeUserType { ref subpattern, .. } = * pat. kind {
2258- pat = subpattern;
2259- }
2260-
22612255 if let NonExhaustive = constructor {
22622256 // Only a wildcard pattern can match the special extra constructor
22632257 return if pat. is_wildcard ( ) { Some ( PatStack :: default ( ) ) } else { None } ;
22642258 }
22652259
22662260 let result = match * pat. kind {
2267- PatKind :: AscribeUserType { .. } => bug ! ( ) , // Handled above
2261+ PatKind :: AscribeUserType { .. } => bug ! ( ) , // Handled by `expand_pattern`
22682262
22692263 PatKind :: Binding { .. } | PatKind :: Wild => {
22702264 Some ( PatStack :: from_slice ( ctor_wild_subpatterns) )
0 commit comments