From 481ed2d9319a28b770da60f4567e55f5cc053835 Mon Sep 17 00:00:00 2001 From: Shunpoco Date: Wed, 22 Jan 2025 01:51:11 +0000 Subject: [PATCH] address review: modify matches/mod.rs The candidate shouldn't have false_edge_start_block if it has sub candidates. In remove_never_subcandidates(), the false_edge_start_block from the first sub candidte is assigned to a value and the value is later used if all sub candidates are removed and candidate doesn't have false_edge_start_block. In merge_trivial_subcandidates, I leave the if block which assign a false_edge_start_block into the candidate as before I put this commit since compile panics. Signed-off-by: Shunpoco --- compiler/rustc_mir_build/src/builder/matches/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_mir_build/src/builder/matches/mod.rs b/compiler/rustc_mir_build/src/builder/matches/mod.rs index 7e7c5ceee937..430854974b38 100644 --- a/compiler/rustc_mir_build/src/builder/matches/mod.rs +++ b/compiler/rustc_mir_build/src/builder/matches/mod.rs @@ -1940,10 +1940,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// in match tree lowering. fn merge_trivial_subcandidates(&mut self, candidate: &mut Candidate<'_, 'tcx>) { assert!(!candidate.subcandidates.is_empty()); - if candidate.false_edge_start_block.is_none() { - candidate.false_edge_start_block = candidate.subcandidates[0].false_edge_start_block; - } - if candidate.has_guard { // FIXME(or_patterns; matthewjasper) Don't give up if we have a guard. return; @@ -1963,6 +1959,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let or_span = candidate.or_span.take().unwrap(); let source_info = self.source_info(or_span); + if candidate.false_edge_start_block.is_none() { + candidate.false_edge_start_block = candidate.subcandidates[0].false_edge_start_block; + } + // Remove the (known-trivial) subcandidates from the candidate tree, // so that they aren't visible after match tree lowering, and wire them // all to join up at a single shared pre-binding block. @@ -1986,6 +1986,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { return; } + let false_edge_start_block = candidate.subcandidates[0].false_edge_start_block; candidate.subcandidates.retain_mut(|candidate| { if candidate.extra_data.is_never { candidate.visit_leaves(|subcandidate| { @@ -2004,6 +2005,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let next_block = self.cfg.start_new_block(); candidate.pre_binding_block = Some(next_block); candidate.otherwise_block = Some(next_block); + // In addition, if `candidate` should have `false_edge_start_block`. + if candidate.false_edge_start_block.is_none() { + candidate.false_edge_start_block = false_edge_start_block; + } } }