Skip to content

Commit bd0334f

Browse files
committed
Cleanup a bit
1 parent 79be3a9 commit bd0334f

File tree

1 file changed

+13
-17
lines changed
  • compiler/rustc_mir_build/src/build/matches

1 file changed

+13
-17
lines changed

compiler/rustc_mir_build/src/build/matches/mod.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12511251
//
12521252
// only generates a single switch.
12531253
let match_pair = candidate.match_pairs.pop().unwrap();
1254-
self.create_or_subcandidates(candidate, &match_pair);
1254+
self.create_or_subcandidates(candidate, match_pair);
12551255
split_or_candidate = true;
12561256
}
12571257
}
@@ -1439,9 +1439,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14391439
return;
14401440
}
14411441

1442-
let match_pairs = mem::take(&mut first_candidate.match_pairs);
1443-
let (first_match_pair, remaining_match_pairs) = match_pairs.split_first().unwrap();
1444-
1442+
let first_match_pair = first_candidate.match_pairs.remove(0);
1443+
let remaining_match_pairs = mem::take(&mut first_candidate.match_pairs);
14451444
let remainder_start = self.cfg.start_new_block();
14461445
// Test the alternatives of this or-pattern.
14471446
self.test_or_pattern(first_candidate, start_block, remainder_start, first_match_pair);
@@ -1485,11 +1484,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14851484
candidate: &mut Candidate<'pat, 'tcx>,
14861485
start_block: BasicBlock,
14871486
otherwise_block: BasicBlock,
1488-
match_pair: &MatchPair<'pat, 'tcx>,
1487+
match_pair: MatchPair<'pat, 'tcx>,
14891488
) {
1489+
let or_span = match_pair.pattern.span;
14901490
self.create_or_subcandidates(candidate, match_pair);
14911491
let mut or_candidate_refs: Vec<_> = candidate.subcandidates.iter_mut().collect();
1492-
let or_span = match_pair.pattern.span;
14931492
self.match_candidates(
14941493
or_span,
14951494
or_span,
@@ -1506,14 +1505,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15061505
fn create_or_subcandidates<'pat>(
15071506
&mut self,
15081507
candidate: &mut Candidate<'pat, 'tcx>,
1509-
match_pair: &MatchPair<'pat, 'tcx>,
1508+
match_pair: MatchPair<'pat, 'tcx>,
15101509
) {
1511-
let TestCase::Or { ref pats } = &match_pair.test_case else { bug!() };
1510+
let TestCase::Or { pats } = match_pair.test_case else { bug!() };
15121511
debug!("expanding or-pattern: candidate={:#?}\npats={:#?}", candidate, pats);
15131512
candidate.or_span = Some(match_pair.pattern.span);
15141513
candidate.subcandidates = pats
1515-
.iter()
1516-
.cloned()
1514+
.into_vec()
1515+
.into_iter()
15171516
.map(|flat_pat| Candidate::from_flat_pat(flat_pat, candidate.has_guard))
15181517
.collect();
15191518
}
@@ -1527,13 +1526,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15271526
return;
15281527
}
15291528

1530-
let mut can_merge = true;
1531-
for subcandidate in &mut candidate.subcandidates {
1532-
// FIXME(or_patterns; matthewjasper) Try to be more aggressive here.
1533-
can_merge &=
1534-
subcandidate.subcandidates.is_empty() && subcandidate.extra_data.is_empty();
1535-
}
1536-
1529+
// FIXME(or_patterns; matthewjasper) Try to be more aggressive here.
1530+
let can_merge = candidate.subcandidates.iter().all(|subcandidate| {
1531+
subcandidate.subcandidates.is_empty() && subcandidate.extra_data.is_empty()
1532+
});
15371533
if can_merge {
15381534
let any_matches = self.cfg.start_new_block();
15391535
let source_info = self.source_info(candidate.or_span.unwrap());

0 commit comments

Comments
 (0)