Tweak block management

This commit is contained in:
Nadrieril 2024-02-18 12:52:40 +01:00
parent 7168c13579
commit 780beda83c

View File

@ -1408,7 +1408,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
span: Span, span: Span,
scrutinee_span: Span, scrutinee_span: Span,
candidates: &mut [&mut Candidate<'_, 'tcx>], candidates: &mut [&mut Candidate<'_, 'tcx>],
block: BasicBlock, start_block: BasicBlock,
otherwise_block: BasicBlock, otherwise_block: BasicBlock,
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>, fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
) { ) {
@ -1423,7 +1423,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
span, span,
scrutinee_span, scrutinee_span,
candidates, candidates,
block, start_block,
otherwise_block, otherwise_block,
fake_borrows, fake_borrows,
); );
@ -1432,7 +1432,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
let match_pairs = mem::take(&mut first_candidate.match_pairs); let match_pairs = mem::take(&mut first_candidate.match_pairs);
first_candidate.pre_binding_block = Some(block);
let remainder_start = self.cfg.start_new_block(); let remainder_start = self.cfg.start_new_block();
for match_pair in match_pairs { for match_pair in match_pairs {
@ -1442,9 +1441,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let or_span = match_pair.pattern.span; let or_span = match_pair.pattern.span;
first_candidate.visit_leaves(|leaf_candidate| { first_candidate.visit_leaves(|leaf_candidate| {
let or_start = leaf_candidate.pre_binding_block.unwrap_or(start_block);
let or_otherwise = leaf_candidate.otherwise_block.unwrap_or(remainder_start);
self.test_or_pattern( self.test_or_pattern(
leaf_candidate, leaf_candidate,
remainder_start, or_start,
or_otherwise,
pats, pats,
or_span, or_span,
&match_pair.place, &match_pair.place,
@ -1464,13 +1466,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
#[instrument( #[instrument(
skip(self, otherwise, or_span, place, fake_borrows, candidate, pats), skip(self, start_block, otherwise_block, or_span, place, fake_borrows, candidate, pats),
level = "debug" level = "debug"
)] )]
fn test_or_pattern<'pat>( fn test_or_pattern<'pat>(
&mut self, &mut self,
candidate: &mut Candidate<'pat, 'tcx>, candidate: &mut Candidate<'pat, 'tcx>,
otherwise: BasicBlock, start_block: BasicBlock,
otherwise_block: BasicBlock,
pats: &'pat [Box<Pat<'tcx>>], pats: &'pat [Box<Pat<'tcx>>],
or_span: Span, or_span: Span,
place: &PlaceBuilder<'tcx>, place: &PlaceBuilder<'tcx>,
@ -1482,16 +1485,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
.map(|pat| Candidate::new(place.clone(), pat, candidate.has_guard, self)) .map(|pat| Candidate::new(place.clone(), pat, candidate.has_guard, self))
.collect(); .collect();
let mut or_candidate_refs: Vec<_> = or_candidates.iter_mut().collect(); let mut or_candidate_refs: Vec<_> = or_candidates.iter_mut().collect();
let otherwise = if let Some(otherwise_block) = candidate.otherwise_block {
otherwise_block
} else {
otherwise
};
self.match_candidates( self.match_candidates(
or_span, or_span,
or_span, or_span,
candidate.pre_binding_block.unwrap(), start_block,
otherwise, otherwise_block,
&mut or_candidate_refs, &mut or_candidate_refs,
fake_borrows, fake_borrows,
); );