@@ -1263,7 +1263,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1263
1263
//
1264
1264
// only generates a single switch.
1265
1265
let match_pair = candidate. match_pairs . pop ( ) . unwrap ( ) ;
1266
- self . create_or_subcandidates ( candidate, & match_pair) ;
1266
+ self . create_or_subcandidates ( candidate, match_pair) ;
1267
1267
split_or_candidate = true ;
1268
1268
}
1269
1269
}
@@ -1451,9 +1451,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1451
1451
return ;
1452
1452
}
1453
1453
1454
- let match_pairs = mem:: take ( & mut first_candidate. match_pairs ) ;
1455
- let ( first_match_pair, remaining_match_pairs) = match_pairs. split_first ( ) . unwrap ( ) ;
1456
-
1454
+ let first_match_pair = first_candidate. match_pairs . remove ( 0 ) ;
1455
+ let remaining_match_pairs = mem:: take ( & mut first_candidate. match_pairs ) ;
1457
1456
let remainder_start = self . cfg . start_new_block ( ) ;
1458
1457
// Test the alternatives of this or-pattern.
1459
1458
self . test_or_pattern ( first_candidate, start_block, remainder_start, first_match_pair) ;
@@ -1497,11 +1496,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1497
1496
candidate : & mut Candidate < ' pat , ' tcx > ,
1498
1497
start_block : BasicBlock ,
1499
1498
otherwise_block : BasicBlock ,
1500
- match_pair : & MatchPair < ' pat , ' tcx > ,
1499
+ match_pair : MatchPair < ' pat , ' tcx > ,
1501
1500
) {
1501
+ let or_span = match_pair. pattern . span ;
1502
1502
self . create_or_subcandidates ( candidate, match_pair) ;
1503
1503
let mut or_candidate_refs: Vec < _ > = candidate. subcandidates . iter_mut ( ) . collect ( ) ;
1504
- let or_span = match_pair. pattern . span ;
1505
1504
self . match_candidates (
1506
1505
or_span,
1507
1506
or_span,
@@ -1518,14 +1517,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1518
1517
fn create_or_subcandidates < ' pat > (
1519
1518
& mut self ,
1520
1519
candidate : & mut Candidate < ' pat , ' tcx > ,
1521
- match_pair : & MatchPair < ' pat , ' tcx > ,
1520
+ match_pair : MatchPair < ' pat , ' tcx > ,
1522
1521
) {
1523
- let TestCase :: Or { ref pats } = & match_pair. test_case else { bug ! ( ) } ;
1522
+ let TestCase :: Or { pats } = match_pair. test_case else { bug ! ( ) } ;
1524
1523
debug ! ( "expanding or-pattern: candidate={:#?}\n pats={:#?}" , candidate, pats) ;
1525
1524
candidate. or_span = Some ( match_pair. pattern . span ) ;
1526
1525
candidate. subcandidates = pats
1527
- . iter ( )
1528
- . cloned ( )
1526
+ . into_vec ( )
1527
+ . into_iter ( )
1529
1528
. map ( |flat_pat| Candidate :: from_flat_pat ( flat_pat, candidate. has_guard ) )
1530
1529
. collect ( ) ;
1531
1530
}
@@ -1539,14 +1538,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1539
1538
return ;
1540
1539
}
1541
1540
1542
- let mut can_merge = true ;
1543
- for subcandidate in & mut candidate. subcandidates {
1544
- // FIXME(or_patterns; matthewjasper) Try to be more aggressive here.
1545
- can_merge &= subcandidate. subcandidates . is_empty ( )
1541
+ // FIXME(or_patterns; matthewjasper) Try to be more aggressive here.
1542
+ let can_merge = candidate. subcandidates . iter ( ) . all ( |subcandidate| {
1543
+ subcandidate. subcandidates . is_empty ( )
1546
1544
&& subcandidate. bindings . is_empty ( )
1547
- && subcandidate. ascriptions . is_empty ( ) ;
1548
- }
1549
-
1545
+ && subcandidate. ascriptions . is_empty ( )
1546
+ } ) ;
1550
1547
if can_merge {
1551
1548
let any_matches = self . cfg . start_new_block ( ) ;
1552
1549
let source_info = self . source_info ( candidate. or_span . unwrap ( ) ) ;
0 commit comments