@@ -104,19 +104,6 @@ struct Scope {
104104 /// the span of that region_scope
105105 region_scope_span : Span ,
106106
107- /// Whether there's anything to do for the cleanup path, that is,
108- /// when unwinding through this scope. This includes destructors,
109- /// but not StorageDead statements, which don't get emitted at all
110- /// for unwinding, for several reasons:
111- /// * clang doesn't emit llvm.lifetime.end for C++ unwinding
112- /// * LLVM's memory dependency analysis can't handle it atm
113- /// * polluting the cleanup MIR with StorageDead creates
114- /// landing pads even though there's no actual destructors
115- /// * freeing up stack space has no effect during unwinding
116- /// Note that for generators we do emit StorageDeads, for the
117- /// use of optimizations in the MIR generator transform.
118- needs_cleanup : bool ,
119-
120107 /// set of places to drop when exiting this scope. This starts
121108 /// out empty but grows as variables are declared during the
122109 /// building process. This is a stack, so we always drop from the
@@ -261,6 +248,25 @@ impl Scope {
261248 scope : self . source_scope
262249 }
263250 }
251+
252+
253+ /// Whether there's anything to do for the cleanup path, that is,
254+ /// when unwinding through this scope. This includes destructors,
255+ /// but not StorageDead statements, which don't get emitted at all
256+ /// for unwinding, for several reasons:
257+ /// * clang doesn't emit llvm.lifetime.end for C++ unwinding
258+ /// * LLVM's memory dependency analysis can't handle it atm
259+ /// * polluting the cleanup MIR with StorageDead creates
260+ /// landing pads even though there's no actual destructors
261+ /// * freeing up stack space has no effect during unwinding
262+ /// Note that for generators we do emit StorageDeads, for the
263+ /// use of optimizations in the MIR generator transform.
264+ fn needs_cleanup ( & self ) -> bool {
265+ self . drops . iter ( ) . any ( |drop| match drop. kind {
266+ DropKind :: Value => true ,
267+ DropKind :: Storage => false ,
268+ } )
269+ }
264270}
265271
266272impl < ' tcx > Scopes < ' tcx > {
@@ -274,7 +280,6 @@ impl<'tcx> Scopes<'tcx> {
274280 source_scope : vis_scope,
275281 region_scope : region_scope. 0 ,
276282 region_scope_span : region_scope. 1 . span ,
277- needs_cleanup : false ,
278283 drops : vec ! [ ] ,
279284 cached_generator_drop : None ,
280285 cached_exits : Default :: default ( ) ,
@@ -295,7 +300,7 @@ impl<'tcx> Scopes<'tcx> {
295300
296301 fn may_panic ( & self , scope_count : usize ) -> bool {
297302 let len = self . len ( ) ;
298- self . scopes [ ( len - scope_count) ..] . iter ( ) . any ( |s| s. needs_cleanup )
303+ self . scopes [ ( len - scope_count) ..] . iter ( ) . any ( |s| s. needs_cleanup ( ) )
299304 }
300305
301306 /// Finds the breakable scope for a given label. This is used for
@@ -801,10 +806,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
801806 // cache of outer scope stays intact.
802807 scope. invalidate_cache ( !needs_drop, self . is_generator , this_scope) ;
803808 if this_scope {
804- if let DropKind :: Value = drop_kind {
805- scope. needs_cleanup = true ;
806- }
807-
808809 let region_scope_span = region_scope. span ( self . hir . tcx ( ) ,
809810 & self . hir . region_scope_tree ) ;
810811 // Attribute scope exit drops to scope's closing brace.
0 commit comments