Skip to content

Commit 780beda

Browse files
committed
Tweak block management
1 parent 7168c13 commit 780beda

File tree

1 file changed

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

1 file changed

+11
-13
lines changed

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

+11-13
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14081408
span: Span,
14091409
scrutinee_span: Span,
14101410
candidates: &mut [&mut Candidate<'_, 'tcx>],
1411-
block: BasicBlock,
1411+
start_block: BasicBlock,
14121412
otherwise_block: BasicBlock,
14131413
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
14141414
) {
@@ -1423,7 +1423,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14231423
span,
14241424
scrutinee_span,
14251425
candidates,
1426-
block,
1426+
start_block,
14271427
otherwise_block,
14281428
fake_borrows,
14291429
);
@@ -1432,7 +1432,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14321432
}
14331433

14341434
let match_pairs = mem::take(&mut first_candidate.match_pairs);
1435-
first_candidate.pre_binding_block = Some(block);
14361435

14371436
let remainder_start = self.cfg.start_new_block();
14381437
for match_pair in match_pairs {
@@ -1442,9 +1441,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14421441
let or_span = match_pair.pattern.span;
14431442

14441443
first_candidate.visit_leaves(|leaf_candidate| {
1444+
let or_start = leaf_candidate.pre_binding_block.unwrap_or(start_block);
1445+
let or_otherwise = leaf_candidate.otherwise_block.unwrap_or(remainder_start);
14451446
self.test_or_pattern(
14461447
leaf_candidate,
1447-
remainder_start,
1448+
or_start,
1449+
or_otherwise,
14481450
pats,
14491451
or_span,
14501452
&match_pair.place,
@@ -1464,13 +1466,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14641466
}
14651467

14661468
#[instrument(
1467-
skip(self, otherwise, or_span, place, fake_borrows, candidate, pats),
1469+
skip(self, start_block, otherwise_block, or_span, place, fake_borrows, candidate, pats),
14681470
level = "debug"
14691471
)]
14701472
fn test_or_pattern<'pat>(
14711473
&mut self,
14721474
candidate: &mut Candidate<'pat, 'tcx>,
1473-
otherwise: BasicBlock,
1475+
start_block: BasicBlock,
1476+
otherwise_block: BasicBlock,
14741477
pats: &'pat [Box<Pat<'tcx>>],
14751478
or_span: Span,
14761479
place: &PlaceBuilder<'tcx>,
@@ -1482,16 +1485,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14821485
.map(|pat| Candidate::new(place.clone(), pat, candidate.has_guard, self))
14831486
.collect();
14841487
let mut or_candidate_refs: Vec<_> = or_candidates.iter_mut().collect();
1485-
let otherwise = if let Some(otherwise_block) = candidate.otherwise_block {
1486-
otherwise_block
1487-
} else {
1488-
otherwise
1489-
};
14901488
self.match_candidates(
14911489
or_span,
14921490
or_span,
1493-
candidate.pre_binding_block.unwrap(),
1494-
otherwise,
1491+
start_block,
1492+
otherwise_block,
14951493
&mut or_candidate_refs,
14961494
fake_borrows,
14971495
);

0 commit comments

Comments
 (0)