@@ -599,9 +599,9 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
599
599
// an or-pattern. Panics if `self` is empty.
600
600
fn expand_or_pat < ' a > ( & ' a self ) -> impl Iterator < Item = PatStack < ' p , ' tcx > > + Captures < ' a > {
601
601
self . head ( ) . flatten_or_pat ( ) . into_iter ( ) . map ( move |pat| {
602
- let mut new_pats = smallvec ! [ pat ] ;
603
- new_pats . extend_from_slice ( & self . pats [ 1 .. ] ) ;
604
- PatStack { pats : new_pats }
602
+ let mut new = self . clone ( ) ;
603
+ new . pats [ 0 ] = pat ;
604
+ new
605
605
} )
606
606
}
607
607
@@ -732,18 +732,11 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
732
732
}
733
733
734
734
/// Build a new matrix from an iterator of `MatchArm`s.
735
- fn new < ' a > (
736
- cx : & MatchCheckCtxt < ' p , ' tcx > ,
737
- iter : impl Iterator < Item = & ' a MatchArm < ' p , ' tcx > > ,
738
- scrut_ty : Ty < ' tcx > ,
739
- ) -> Self
740
- where
741
- ' p : ' a ,
742
- {
735
+ fn new ( cx : & MatchCheckCtxt < ' p , ' tcx > , arms : & [ MatchArm < ' p , ' tcx > ] , scrut_ty : Ty < ' tcx > ) -> Self {
743
736
let wild_pattern = cx. pattern_arena . alloc ( DeconstructedPat :: wildcard ( scrut_ty, DUMMY_SP ) ) ;
744
737
let wildcard_row = PatStack :: from_pattern ( wild_pattern) ;
745
- let mut matrix = Matrix { rows : vec ! [ ] , wildcard_row } ;
746
- for ( row_id, arm) in iter. enumerate ( ) {
738
+ let mut matrix = Matrix { rows : Vec :: with_capacity ( arms . len ( ) ) , wildcard_row } ;
739
+ for ( row_id, arm) in arms . iter ( ) . enumerate ( ) {
747
740
let v = MatrixRow {
748
741
pats : PatStack :: from_pattern ( arm. pat ) ,
749
742
parent_row : row_id, // dummy, we won't read it
@@ -806,7 +799,7 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> {
806
799
ctor : & Constructor < ' tcx > ,
807
800
) -> Matrix < ' p , ' tcx > {
808
801
let wildcard_row = self . wildcard_row . pop_head_constructor ( pcx, ctor) ;
809
- let mut matrix = Matrix { rows : vec ! [ ] , wildcard_row } ;
802
+ let mut matrix = Matrix { rows : Vec :: new ( ) , wildcard_row } ;
810
803
for ( i, row) in self . rows ( ) . enumerate ( ) {
811
804
if ctor. is_covered_by ( pcx, row. head ( ) . ctor ( ) ) {
812
805
let new_row = row. pop_head_constructor ( pcx, ctor, i) ;
@@ -1386,7 +1379,7 @@ pub(crate) fn compute_match_usefulness<'p, 'tcx>(
1386
1379
arms : & [ MatchArm < ' p , ' tcx > ] ,
1387
1380
scrut_ty : Ty < ' tcx > ,
1388
1381
) -> UsefulnessReport < ' p , ' tcx > {
1389
- let mut matrix = Matrix :: new ( cx, arms. iter ( ) , scrut_ty) ;
1382
+ let mut matrix = Matrix :: new ( cx, arms, scrut_ty) ;
1390
1383
let non_exhaustiveness_witnesses =
1391
1384
compute_exhaustiveness_and_reachability ( cx, & mut matrix, true ) ;
1392
1385
0 commit comments