diff options
| author | Ding Xiang Fei <dingxiangfei2009@protonmail.ch> | 2022-10-05 22:24:12 +0800 |
|---|---|---|
| committer | Ding Xiang Fei <dingxiangfei2009@protonmail.ch> | 2022-10-05 22:24:12 +0800 |
| commit | 565c35aa5c3c39626fcd332bafbd8936b70ed989 (patch) | |
| tree | bc5a9c4b3fc0009be39d2b63d3cb8b081f9e3587 | |
| parent | 5131e9db07fb6cd158cf5bf2aa9fefbad3af1d2b (diff) | |
| download | rust-565c35aa5c3c39626fcd332bafbd8936b70ed989.tar.gz rust-565c35aa5c3c39626fcd332bafbd8936b70ed989.zip | |
fix doc and dedup diverge_cleanup
| -rw-r--r-- | compiler/rustc_mir_build/src/build/scope.rs | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/compiler/rustc_mir_build/src/build/scope.rs b/compiler/rustc_mir_build/src/build/scope.rs index edace55f572..3cebd5ebed6 100644 --- a/compiler/rustc_mir_build/src/build/scope.rs +++ b/compiler/rustc_mir_build/src/build/scope.rs @@ -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. |
