From 105bdf708606258a5d70e8bed4b576663bcc2672 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 16 Feb 2024 04:16:19 +0100 Subject: [PATCH] Reuse `next_prebinding` The moment we get a candidate without guard, the return block becomes a fresh block linked to nothing. So we can keep assigning a fresh block every iteration to reuse the `next_prebinding` logic. --- compiler/rustc_mir_build/src/build/matches/mod.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 5a5daa949b02..17f3d206232f 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -1315,29 +1315,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let mut next_prebinding = start_block; let mut reachable = true; - let mut return_block = None; for candidate in matched_candidates.iter_mut() { assert!(candidate.otherwise_block.is_none()); assert!(candidate.pre_binding_block.is_none()); + candidate.pre_binding_block = Some(next_prebinding); + next_prebinding = self.cfg.start_new_block(); if reachable { - candidate.pre_binding_block = Some(next_prebinding); if candidate.has_guard { // Create the otherwise block for this candidate, which is the // pre-binding block for the next candidate. - next_prebinding = self.cfg.start_new_block(); candidate.otherwise_block = Some(next_prebinding); - return_block = Some(next_prebinding); } else { reachable = false; - return_block = Some(self.cfg.start_new_block()); } - } else { - candidate.pre_binding_block = Some(self.cfg.start_new_block()); } } - return_block.unwrap() + next_prebinding } /// Tests a candidate where there are only or-patterns left to test, or