Skip to content

Commit 886668c

Browse files
committed
Improve test_remaining_match_pairs_after_or
1 parent e60c5c1 commit 886668c

File tree

1 file changed

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

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,10 +1808,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
18081808
candidate.visit_leaves(|leaf_candidate| {
18091809
last_otherwise = leaf_candidate.otherwise_block;
18101810
});
1811+
18111812
let remaining_match_pairs = mem::take(&mut candidate.match_pairs);
1813+
// We're testing match pairs that remained after an `Or`, so the remaining
1814+
// pairs should all be `Or` too, due to the sorting invariant.
1815+
debug_assert!(
1816+
remaining_match_pairs
1817+
.iter()
1818+
.all(|match_pair| matches!(match_pair.test_case, TestCase::Or { .. }))
1819+
);
1820+
18121821
candidate.visit_leaves(|leaf_candidate| {
1822+
// At this point the leaf's own match pairs have all been lowered
1823+
// and removed, so `extend` and assignment are equivalent,
1824+
// but extending can also recycle any existing vector capacity.
18131825
assert!(leaf_candidate.match_pairs.is_empty());
18141826
leaf_candidate.match_pairs.extend(remaining_match_pairs.iter().cloned());
1827+
18151828
let or_start = leaf_candidate.pre_binding_block.unwrap();
18161829
let otherwise =
18171830
self.match_candidates(span, scrutinee_span, or_start, &mut [leaf_candidate]);

0 commit comments

Comments
 (0)