@@ -557,14 +557,13 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
557
557
ty:: Slice ( ..) |
558
558
ty:: Array ( ..) =>
559
559
self . slice_or_array_pattern ( pat. span , ty, prefix, slice, suffix) ,
560
- ty:: Error => { // Avoid ICE
561
- return Pat { span : pat. span , ty, kind : Box :: new ( PatKind :: Wild ) } ;
562
- }
563
- _ =>
564
- span_bug ! (
565
- pat. span,
566
- "unexpanded type for vector pattern: {:?}" ,
567
- ty) ,
560
+ // Avoid ICE
561
+ ty:: Error => return Pat { span : pat. span , ty, kind : Box :: new ( PatKind :: Wild ) } ,
562
+ _ => span_bug ! (
563
+ pat. span,
564
+ "unexpanded type for vector pattern: {:?}" ,
565
+ ty
566
+ ) ,
568
567
}
569
568
}
570
569
@@ -698,9 +697,8 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
698
697
& mut self ,
699
698
prefix : Vec < Pat < ' tcx > > ,
700
699
slice : Option < Pat < ' tcx > > ,
701
- suffix : Vec < Pat < ' tcx > > )
702
- -> ( Vec < Pat < ' tcx > > , Option < Pat < ' tcx > > , Vec < Pat < ' tcx > > )
703
- {
700
+ suffix : Vec < Pat < ' tcx > > ,
701
+ ) -> ( Vec < Pat < ' tcx > > , Option < Pat < ' tcx > > , Vec < Pat < ' tcx > > ) {
704
702
let orig_slice = match slice {
705
703
Some ( orig_slice) => orig_slice,
706
704
None => return ( prefix, slice, suffix)
@@ -734,31 +732,24 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
734
732
ty : Ty < ' tcx > ,
735
733
prefix : & ' tcx [ P < hir:: Pat > ] ,
736
734
slice : & ' tcx Option < P < hir:: Pat > > ,
737
- suffix : & ' tcx [ P < hir:: Pat > ] )
738
- -> PatKind < ' tcx >
739
- {
735
+ suffix : & ' tcx [ P < hir:: Pat > ] ,
736
+ ) -> PatKind < ' tcx > {
740
737
let prefix = self . lower_patterns ( prefix) ;
741
738
let slice = self . lower_opt_pattern ( slice) ;
742
739
let suffix = self . lower_patterns ( suffix) ;
743
- let ( prefix, slice, suffix) =
744
- self . flatten_nested_slice_patterns ( prefix, slice, suffix) ;
740
+ let ( prefix, slice, suffix) = self . flatten_nested_slice_patterns ( prefix, slice, suffix) ;
745
741
742
+ // Some validation:
746
743
match ty. kind {
747
- ty:: Slice ( ..) => {
748
- // matching a slice or fixed-length array
749
- PatKind :: Slice { prefix : prefix, slice : slice, suffix : suffix }
750
- }
751
-
744
+ // Matching a slice, `[T]`.
745
+ ty:: Slice ( ..) => PatKind :: Slice { prefix, slice, suffix } ,
746
+ // Fixed-length array, `[T; len]`.
752
747
ty:: Array ( _, len) => {
753
- // fixed-length array
754
748
let len = len. eval_usize ( self . tcx , self . param_env ) ;
755
749
assert ! ( len >= prefix. len( ) as u64 + suffix. len( ) as u64 ) ;
756
- PatKind :: Array { prefix : prefix, slice : slice, suffix : suffix }
757
- }
758
-
759
- _ => {
760
- span_bug ! ( span, "bad slice pattern type {:?}" , ty) ;
750
+ PatKind :: Array { prefix, slice, suffix }
761
751
}
752
+ _ => span_bug ! ( span, "bad slice pattern type {:?}" , ty) ,
762
753
}
763
754
}
764
755
0 commit comments