about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2024-02-18 12:52:40 +0100
committerNadrieril <nadrieril+git@gmail.com>2024-02-21 11:25:11 +0100
commit780beda83c8b822a91b801050ee543f5f7a271df (patch)
treee8b8820adc7039c1474befd9a344372a0afac30a
parent7168c13579a550f2c47f7eea22f5e226a436cd00 (diff)
downloadrust-780beda83c8b822a91b801050ee543f5f7a271df.tar.gz
rust-780beda83c8b822a91b801050ee543f5f7a271df.zip
Tweak block management
-rw-r--r--compiler/rustc_mir_build/src/build/matches/mod.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs
index ccf299649cf..808b4a130e5 100644
--- a/compiler/rustc_mir_build/src/build/matches/mod.rs
+++ b/compiler/rustc_mir_build/src/build/matches/mod.rs
@@ -1408,7 +1408,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         span: Span,
         scrutinee_span: Span,
         candidates: &mut [&mut Candidate<'_, 'tcx>],
-        block: BasicBlock,
+        start_block: BasicBlock,
         otherwise_block: BasicBlock,
         fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
     ) {
@@ -1423,7 +1423,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                     span,
                     scrutinee_span,
                     candidates,
-                    block,
+                    start_block,
                     otherwise_block,
                     fake_borrows,
                 );
@@ -1432,7 +1432,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
         }
 
         let match_pairs = mem::take(&mut first_candidate.match_pairs);
-        first_candidate.pre_binding_block = Some(block);
 
         let remainder_start = self.cfg.start_new_block();
         for match_pair in match_pairs {
@@ -1442,9 +1441,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
             let or_span = match_pair.pattern.span;
 
             first_candidate.visit_leaves(|leaf_candidate| {
+                let or_start = leaf_candidate.pre_binding_block.unwrap_or(start_block);
+                let or_otherwise = leaf_candidate.otherwise_block.unwrap_or(remainder_start);
                 self.test_or_pattern(
                     leaf_candidate,
-                    remainder_start,
+                    or_start,
+                    or_otherwise,
                     pats,
                     or_span,
                     &match_pair.place,
@@ -1464,13 +1466,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
     }
 
     #[instrument(
-        skip(self, otherwise, or_span, place, fake_borrows, candidate, pats),
+        skip(self, start_block, otherwise_block, or_span, place, fake_borrows, candidate, pats),
         level = "debug"
     )]
     fn test_or_pattern<'pat>(
         &mut self,
         candidate: &mut Candidate<'pat, 'tcx>,
-        otherwise: BasicBlock,
+        start_block: BasicBlock,
+        otherwise_block: BasicBlock,
         pats: &'pat [Box<Pat<'tcx>>],
         or_span: Span,
         place: &PlaceBuilder<'tcx>,
@@ -1482,16 +1485,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
             .map(|pat| Candidate::new(place.clone(), pat, candidate.has_guard, self))
             .collect();
         let mut or_candidate_refs: Vec<_> = or_candidates.iter_mut().collect();
-        let otherwise = if let Some(otherwise_block) = candidate.otherwise_block {
-            otherwise_block
-        } else {
-            otherwise
-        };
         self.match_candidates(
             or_span,
             or_span,
-            candidate.pre_binding_block.unwrap(),
-            otherwise,
+            start_block,
+            otherwise_block,
             &mut or_candidate_refs,
             fake_borrows,
         );