From 886668cc2ea22a3d52f775961bac06d9499d9e26 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 18 Jul 2024 22:34:49 +1000 Subject: [PATCH] Improve `test_remaining_match_pairs_after_or` --- compiler/rustc_mir_build/src/build/matches/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 8bba9329085..d8db08bfb8a 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -1808,10 +1808,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { candidate.visit_leaves(|leaf_candidate| { last_otherwise = leaf_candidate.otherwise_block; }); + let remaining_match_pairs = mem::take(&mut candidate.match_pairs); + // We're testing match pairs that remained after an `Or`, so the remaining + // pairs should all be `Or` too, due to the sorting invariant. + debug_assert!( + remaining_match_pairs + .iter() + .all(|match_pair| matches!(match_pair.test_case, TestCase::Or { .. })) + ); + candidate.visit_leaves(|leaf_candidate| { + // At this point the leaf's own match pairs have all been lowered + // and removed, so `extend` and assignment are equivalent, + // but extending can also recycle any existing vector capacity. assert!(leaf_candidate.match_pairs.is_empty()); leaf_candidate.match_pairs.extend(remaining_match_pairs.iter().cloned()); + let or_start = leaf_candidate.pre_binding_block.unwrap(); let otherwise = self.match_candidates(span, scrutinee_span, or_start, &mut [leaf_candidate]);