Skip to content

Commit 15de647

Browse files
committed
Cleanup a bit
1 parent e211701 commit 15de647

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
@@ -1283,7 +1283,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12831283
//
12841284
// only generates a single switch.
12851285
let match_pair = candidate.match_pairs.pop().unwrap();
1286-
self.create_or_subcandidates(candidate, &match_pair);
1286+
self.create_or_subcandidates(candidate, match_pair);
12871287
split_or_candidate = true;
12881288
}
12891289
}
@@ -1471,9 +1471,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14711471
return;
14721472
}
14731473

1474-
let match_pairs = mem::take(&mut first_candidate.match_pairs);
1475-
let (first_match_pair, remaining_match_pairs) = match_pairs.split_first().unwrap();
1476-
1474+
let first_match_pair = first_candidate.match_pairs.remove(0);
1475+
let remaining_match_pairs = mem::take(&mut first_candidate.match_pairs);
14771476
let remainder_start = self.cfg.start_new_block();
14781477
// Test the alternatives of this or-pattern.
14791478
self.test_or_pattern(first_candidate, start_block, remainder_start, first_match_pair);
@@ -1517,11 +1516,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15171516
candidate: &mut Candidate<'pat, 'tcx>,
15181517
start_block: BasicBlock,
15191518
otherwise_block: BasicBlock,
1520-
match_pair: &MatchPair<'pat, 'tcx>,
1519+
match_pair: MatchPair<'pat, 'tcx>,
15211520
) {
1521+
let or_span = match_pair.pattern.span;
15221522
self.create_or_subcandidates(candidate, match_pair);
15231523
let mut or_candidate_refs: Vec<_> = candidate.subcandidates.iter_mut().collect();
1524-
let or_span = match_pair.pattern.span;
15251524
self.match_candidates(
15261525
or_span,
15271526
or_span,
@@ -1538,14 +1537,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15381537
fn create_or_subcandidates<'pat>(
15391538
&mut self,
15401539
candidate: &mut Candidate<'pat, 'tcx>,
1541-
match_pair: &MatchPair<'pat, 'tcx>,
1540+
match_pair: MatchPair<'pat, 'tcx>,
15421541
) {
1543-
let TestCase::Or { ref pats } = &match_pair.test_case else { bug!() };
1542+
let TestCase::Or { pats } = match_pair.test_case else { bug!() };
15441543
debug!("expanding or-pattern: candidate={:#?}\npats={:#?}", candidate, pats);
15451544
candidate.or_span = Some(match_pair.pattern.span);
15461545
candidate.subcandidates = pats
1547-
.iter()
1548-
.cloned()
1546+
.into_vec()
1547+
.into_iter()
15491548
.map(|flat_pat| Candidate::from_flat_pat(flat_pat, candidate.has_guard))
15501549
.collect();
15511550
}
@@ -1559,13 +1558,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15591558
return;
15601559
}
15611560

1562-
let mut can_merge = true;
1563-
for subcandidate in &mut candidate.subcandidates {
1564-
// FIXME(or_patterns; matthewjasper) Try to be more aggressive here.
1565-
can_merge &=
1566-
subcandidate.subcandidates.is_empty() && subcandidate.extra_data.is_empty();
1567-
}
1568-
1561+
// FIXME(or_patterns; matthewjasper) Try to be more aggressive here.
1562+
let can_merge = candidate.subcandidates.iter().all(|subcandidate| {
1563+
subcandidate.subcandidates.is_empty() && subcandidate.extra_data.is_empty()
1564+
});
15691565
if can_merge {
15701566
let any_matches = self.cfg.start_new_block();
15711567
let or_span = candidate.or_span.take().unwrap();

0 commit comments

Comments
 (0)