Skip to content

Commit c7a1c2b

Browse files
committed
Cleanup a bit
1 parent 611d712 commit c7a1c2b

File tree

1 file changed

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

1 file changed

+14
-17
lines changed

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

+14-17
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12631263
//
12641264
// only generates a single switch.
12651265
let match_pair = candidate.match_pairs.pop().unwrap();
1266-
self.create_or_subcandidates(candidate, &match_pair);
1266+
self.create_or_subcandidates(candidate, match_pair);
12671267
split_or_candidate = true;
12681268
}
12691269
}
@@ -1451,9 +1451,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14511451
return;
14521452
}
14531453

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);
14571456
let remainder_start = self.cfg.start_new_block();
14581457
// Test the alternatives of this or-pattern.
14591458
self.test_or_pattern(first_candidate, start_block, remainder_start, first_match_pair);
@@ -1497,11 +1496,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14971496
candidate: &mut Candidate<'pat, 'tcx>,
14981497
start_block: BasicBlock,
14991498
otherwise_block: BasicBlock,
1500-
match_pair: &MatchPair<'pat, 'tcx>,
1499+
match_pair: MatchPair<'pat, 'tcx>,
15011500
) {
1501+
let or_span = match_pair.pattern.span;
15021502
self.create_or_subcandidates(candidate, match_pair);
15031503
let mut or_candidate_refs: Vec<_> = candidate.subcandidates.iter_mut().collect();
1504-
let or_span = match_pair.pattern.span;
15051504
self.match_candidates(
15061505
or_span,
15071506
or_span,
@@ -1518,14 +1517,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15181517
fn create_or_subcandidates<'pat>(
15191518
&mut self,
15201519
candidate: &mut Candidate<'pat, 'tcx>,
1521-
match_pair: &MatchPair<'pat, 'tcx>,
1520+
match_pair: MatchPair<'pat, 'tcx>,
15221521
) {
1523-
let TestCase::Or { ref pats } = &match_pair.test_case else { bug!() };
1522+
let TestCase::Or { pats } = match_pair.test_case else { bug!() };
15241523
debug!("expanding or-pattern: candidate={:#?}\npats={:#?}", candidate, pats);
15251524
candidate.or_span = Some(match_pair.pattern.span);
15261525
candidate.subcandidates = pats
1527-
.iter()
1528-
.cloned()
1526+
.into_vec()
1527+
.into_iter()
15291528
.map(|flat_pat| Candidate::from_flat_pat(flat_pat, candidate.has_guard))
15301529
.collect();
15311530
}
@@ -1539,14 +1538,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15391538
return;
15401539
}
15411540

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()
15461544
&& subcandidate.bindings.is_empty()
1547-
&& subcandidate.ascriptions.is_empty();
1548-
}
1549-
1545+
&& subcandidate.ascriptions.is_empty()
1546+
});
15501547
if can_merge {
15511548
let any_matches = self.cfg.start_new_block();
15521549
let source_info = self.source_info(candidate.or_span.unwrap());

0 commit comments

Comments
 (0)