Skip to content

Commit

Permalink
Cleanup a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Mar 5, 2024
1 parent 611d712 commit c7a1c2b
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
//
// only generates a single switch.
let match_pair = candidate.match_pairs.pop().unwrap();
self.create_or_subcandidates(candidate, &match_pair);
self.create_or_subcandidates(candidate, match_pair);
split_or_candidate = true;
}
}
Expand Down Expand Up @@ -1451,9 +1451,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
return;
}

let match_pairs = mem::take(&mut first_candidate.match_pairs);
let (first_match_pair, remaining_match_pairs) = match_pairs.split_first().unwrap();

let first_match_pair = first_candidate.match_pairs.remove(0);
let remaining_match_pairs = mem::take(&mut first_candidate.match_pairs);
let remainder_start = self.cfg.start_new_block();
// Test the alternatives of this or-pattern.
self.test_or_pattern(first_candidate, start_block, remainder_start, first_match_pair);
Expand Down Expand Up @@ -1497,11 +1496,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
candidate: &mut Candidate<'pat, 'tcx>,
start_block: BasicBlock,
otherwise_block: BasicBlock,
match_pair: &MatchPair<'pat, 'tcx>,
match_pair: MatchPair<'pat, 'tcx>,
) {
let or_span = match_pair.pattern.span;
self.create_or_subcandidates(candidate, match_pair);
let mut or_candidate_refs: Vec<_> = candidate.subcandidates.iter_mut().collect();
let or_span = match_pair.pattern.span;
self.match_candidates(
or_span,
or_span,
Expand All @@ -1518,14 +1517,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn create_or_subcandidates<'pat>(
&mut self,
candidate: &mut Candidate<'pat, 'tcx>,
match_pair: &MatchPair<'pat, 'tcx>,
match_pair: MatchPair<'pat, 'tcx>,
) {
let TestCase::Or { ref pats } = &match_pair.test_case else { bug!() };
let TestCase::Or { pats } = match_pair.test_case else { bug!() };
debug!("expanding or-pattern: candidate={:#?}\npats={:#?}", candidate, pats);
candidate.or_span = Some(match_pair.pattern.span);
candidate.subcandidates = pats
.iter()
.cloned()
.into_vec()
.into_iter()
.map(|flat_pat| Candidate::from_flat_pat(flat_pat, candidate.has_guard))
.collect();
}
Expand All @@ -1539,14 +1538,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
return;
}

let mut can_merge = true;
for subcandidate in &mut candidate.subcandidates {
// FIXME(or_patterns; matthewjasper) Try to be more aggressive here.
can_merge &= subcandidate.subcandidates.is_empty()
// FIXME(or_patterns; matthewjasper) Try to be more aggressive here.
let can_merge = candidate.subcandidates.iter().all(|subcandidate| {
subcandidate.subcandidates.is_empty()
&& subcandidate.bindings.is_empty()
&& subcandidate.ascriptions.is_empty();
}

&& subcandidate.ascriptions.is_empty()
});
if can_merge {
let any_matches = self.cfg.start_new_block();
let source_info = self.source_info(candidate.or_span.unwrap());
Expand Down

0 comments on commit c7a1c2b

Please sign in to comment.