diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2024-03-01 22:13:03 +1100 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2024-03-07 23:11:18 +1100 |
| commit | 570376c49647d8565a639e9e190916fe2246c26f (patch) | |
| tree | a9d10d5c1be6084f4c9914512b86dce40d20741e /compiler/rustc_mir_build/src/build/scope.rs | |
| parent | 51f483944db3675eba6fd82e0c2cc2b57b04a4e0 (diff) | |
| download | rust-570376c49647d8565a639e9e190916fe2246c26f.tar.gz rust-570376c49647d8565a639e9e190916fe2246c26f.zip | |
Don't pass a break scope to `Builder::break_for_else`
This method would previously take a target scope, and then verify that it was equal to the scope on top of the if-then scope stack. In practice, this means that callers have to go out of their way to pass around redundant scope information that's already on the if-then stack. So it's easier to just retrieve the correct scope directly from the if-then stack, and simplify the other code that was passing it around.
Diffstat (limited to 'compiler/rustc_mir_build/src/build/scope.rs')
| -rw-r--r-- | compiler/rustc_mir_build/src/build/scope.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index 04740a96291..961502566ba 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -683,20 +683,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.cfg.start_new_block().unit() } - pub(crate) fn break_for_else( - &mut self, - block: BasicBlock, - target: region::Scope, - source_info: SourceInfo, - ) { - let scope_index = self.scopes.scope_index(target, source_info.span); + /// Sets up the drops for breaking from `block` due to an `if` condition + /// that turned out to be false. + /// + /// Must be called in the context of [`Builder::in_if_then_scope`], so that + /// there is an if-then scope to tell us what the target scope is. + pub(crate) fn break_for_else(&mut self, block: BasicBlock, source_info: SourceInfo) { let if_then_scope = self .scopes .if_then_scope - .as_mut() + .as_ref() .unwrap_or_else(|| span_bug!(source_info.span, "no if-then scope found")); - assert_eq!(if_then_scope.region_scope, target, "breaking to incorrect scope"); + let target = if_then_scope.region_scope; + let scope_index = self.scopes.scope_index(target, source_info.span); + + // Upgrade `if_then_scope` to `&mut`. + let if_then_scope = self.scopes.if_then_scope.as_mut().expect("upgrading & to &mut"); let mut drop_idx = ROOT_NODE; let drops = &mut if_then_scope.else_drops; |
