about summary refs log tree commit diff
diff options
context:
space:
mode:
authorShunpoco <tkngsnsk313320@gmail.com>2025-01-22 01:51:11 +0000
committerShunpoco <tkngsnsk313320@gmail.com>2025-01-22 01:55:58 +0000
commit481ed2d9319a28b770da60f4567e55f5cc053835 (patch)
treebff00506b5c5b5a46bef3c63c4f1dd6d74d33123
parentd8a216b866ff238589005fb1ea4c54644d8d24bf (diff)
downloadrust-481ed2d9319a28b770da60f4567e55f5cc053835.tar.gz
rust-481ed2d9319a28b770da60f4567e55f5cc053835.zip
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 <tkngsnsk313320@gmail.com>
-rw-r--r--compiler/rustc_mir_build/src/builder/matches/mod.rs13
1 files 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 7e7c5ceee93..430854974b3 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;
+            }
         }
     }