Skip to content

Commit

Permalink
fix doc and dedup diverge_cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiangfei2009 committed Oct 5, 2022
1 parent 5131e9d commit 565c35a
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions compiler/rustc_mir_build/src/build/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,31 +999,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Returns the [DropIdx] for the innermost drop if the function unwound at
/// this point. The `DropIdx` will be created if it doesn't already exist.
fn diverge_cleanup(&mut self) -> DropIdx {
let is_generator = self.generator_kind.is_some();
let (uncached_scope, mut cached_drop) = self
.scopes
.scopes
.iter()
.enumerate()
.rev()
.find_map(|(scope_idx, scope)| {
scope.cached_unwind_block.map(|cached_block| (scope_idx + 1, cached_block))
})
.unwrap_or((0, ROOT_NODE));

for scope in &mut self.scopes.scopes[uncached_scope..] {
for drop in &scope.drops {
if is_generator || drop.kind == DropKind::Value {
cached_drop = self.scopes.unwind_drops.add_drop(*drop, cached_drop);
}
}
scope.cached_unwind_block = Some(cached_drop);
}

cached_drop
// It is okay to use dummy span because the getting scope index on the topmost scope
// must always succeed.
self.diverge_cleanup_target(self.scopes.topmost(), DUMMY_SP)
}

/// This is similar to [diverge_cleanup] except its target is set to
/// This is similar to [diverge_cleanup](Self::diverge_cleanup) except its target is set to
/// some ancestor scope instead of the current scope.
/// It is possible to unwind to some ancestor scope if some drop panics as
/// the program breaks out of a if-then scope.
Expand Down

0 comments on commit 565c35a

Please sign in to comment.