@@ -104,19 +104,6 @@ struct Scope {
104
104
/// the span of that region_scope
105
105
region_scope_span : Span ,
106
106
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
-
120
107
/// set of places to drop when exiting this scope. This starts
121
108
/// out empty but grows as variables are declared during the
122
109
/// building process. This is a stack, so we always drop from the
@@ -261,6 +248,25 @@ impl Scope {
261
248
scope : self . source_scope
262
249
}
263
250
}
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
+ }
264
270
}
265
271
266
272
impl < ' tcx > Scopes < ' tcx > {
@@ -274,7 +280,6 @@ impl<'tcx> Scopes<'tcx> {
274
280
source_scope : vis_scope,
275
281
region_scope : region_scope. 0 ,
276
282
region_scope_span : region_scope. 1 . span ,
277
- needs_cleanup : false ,
278
283
drops : vec ! [ ] ,
279
284
cached_generator_drop : None ,
280
285
cached_exits : Default :: default ( ) ,
@@ -295,7 +300,7 @@ impl<'tcx> Scopes<'tcx> {
295
300
296
301
fn may_panic ( & self , scope_count : usize ) -> bool {
297
302
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 ( ) )
299
304
}
300
305
301
306
/// Finds the breakable scope for a given label. This is used for
@@ -801,10 +806,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
801
806
// cache of outer scope stays intact.
802
807
scope. invalidate_cache ( !needs_drop, self . is_generator , this_scope) ;
803
808
if this_scope {
804
- if let DropKind :: Value = drop_kind {
805
- scope. needs_cleanup = true ;
806
- }
807
-
808
809
let region_scope_span = region_scope. span ( self . hir . tcx ( ) ,
809
810
& self . hir . region_scope_tree ) ;
810
811
// Attribute scope exit drops to scope's closing brace.
0 commit comments