@@ -132,7 +132,7 @@ struct Scope {
132
132
struct DropData {
133
133
/// The `Span` where drop obligation was incurred (typically where place was
134
134
/// declared)
135
- span : Span ,
135
+ source_info : SourceInfo ,
136
136
137
137
/// local to drop
138
138
local : Local ,
@@ -177,8 +177,7 @@ const CONTINUE_NODE: DropIdx = DropIdx::from_u32_const(1);
177
177
// TODO say some more.
178
178
#[ derive( Debug ) ]
179
179
struct DropTree {
180
- /// The next item to drop, if there is one.
181
- // TODO actual comment
180
+ /// Drops in the tree.
182
181
drops : IndexVec < DropIdx , ( DropData , DropIdx ) > ,
183
182
/// Map for finding the inverse of the `next_drop` relation:
184
183
///
@@ -191,14 +190,6 @@ struct DropTree {
191
190
}
192
191
193
192
impl Scope {
194
- /// Given a span and this scope's source scope, make a SourceInfo.
195
- fn source_info ( & self , span : Span ) -> SourceInfo {
196
- SourceInfo {
197
- span,
198
- scope : self . source_scope
199
- }
200
- }
201
-
202
193
/// Whether there's anything to do for the cleanup path, that is,
203
194
/// when unwinding through this scope. This includes destructors,
204
195
/// but not StorageDead statements, which don't get emitted at all
@@ -220,7 +211,12 @@ impl Scope {
220
211
221
212
impl DropTree {
222
213
fn new ( num_roots : usize ) -> Self {
223
- let fake_data = DropData { span : DUMMY_SP , local : Local :: MAX , kind : DropKind :: Storage } ;
214
+ let fake_source_info = SourceInfo { span : DUMMY_SP , scope : OUTERMOST_SOURCE_SCOPE } ;
215
+ let fake_data = DropData {
216
+ source_info : fake_source_info,
217
+ local : Local :: MAX ,
218
+ kind : DropKind :: Storage ,
219
+ } ;
224
220
let drop_idx = DropIdx :: MAX ;
225
221
let drops = IndexVec :: from_elem_n ( ( fake_data, drop_idx) , num_roots) ;
226
222
Self {
@@ -290,10 +286,6 @@ impl<'tcx> Scopes<'tcx> {
290
286
fn topmost ( & self ) -> region:: Scope {
291
287
self . scopes . last ( ) . expect ( "topmost_scope: no scopes present" ) . region_scope
292
288
}
293
-
294
- // fn source_info(&self, index: usize, span: Span) -> SourceInfo {
295
- // self.scopes[self.len() - index].source_info(span)
296
- // }
297
289
}
298
290
299
291
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
@@ -495,7 +487,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
495
487
self . cfg . start_new_block ( ) . unit ( )
496
488
}
497
489
498
- // TODO: use in pop_top_scope.
499
490
crate fn exit_top_scope (
500
491
& mut self ,
501
492
mut block : BasicBlock ,
@@ -678,7 +669,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
678
669
let scope_end = self . hir . tcx ( ) . sess . source_map ( ) . end_point ( region_scope_span) ;
679
670
680
671
scope. drops . push ( DropData {
681
- span : scope_end,
672
+ source_info : SourceInfo { span : scope_end, scope : scope . source_scope } ,
682
673
local,
683
674
kind : drop_kind,
684
675
} ) ;
@@ -791,7 +782,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
791
782
bug ! ( "Drop scheduled on top of condition variable" )
792
783
}
793
784
DropKind :: Storage => {
794
- let source_info = top_scope . source_info ( top_drop_data. span ) ;
785
+ let source_info = top_drop_data. source_info ;
795
786
let local = top_drop_data. local ;
796
787
assert_eq ! ( local, cond_temp, "Drop scheduled on top of condition" ) ;
797
788
self . cfg . push (
@@ -933,7 +924,7 @@ fn build_scope_drops<'tcx>(
933
924
// `diverge_cleanup_gen`.
934
925
935
926
for drop_data in scope. drops . iter ( ) . rev ( ) {
936
- let source_info = scope . source_info ( drop_data. span ) ;
927
+ let source_info = drop_data. source_info ;
937
928
let local = drop_data. local ;
938
929
939
930
match drop_data. kind {
@@ -1127,13 +1118,6 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
1127
1118
}
1128
1119
}
1129
1120
1130
- fn source_info ( span : Span ) -> SourceInfo {
1131
- SourceInfo {
1132
- span,
1133
- scope : OUTERMOST_SOURCE_SCOPE ,
1134
- }
1135
- }
1136
-
1137
1121
fn build_drop_tree < ' tcx , T : DropTreeBuilder < ' tcx > > (
1138
1122
cfg : & mut CFG < ' tcx > ,
1139
1123
drops : & mut DropTree ,
@@ -1207,7 +1191,7 @@ fn build_drop_tree<'tcx, T: DropTreeBuilder<'tcx>>(
1207
1191
} ;
1208
1192
cfg. terminate (
1209
1193
blocks[ drop_idx] . unwrap ( ) ,
1210
- source_info ( drop_data. 0 . span ) ,
1194
+ drop_data. 0 . source_info ,
1211
1195
terminator,
1212
1196
) ;
1213
1197
}
@@ -1216,14 +1200,14 @@ fn build_drop_tree<'tcx, T: DropTreeBuilder<'tcx>>(
1216
1200
DropKind :: Storage => {
1217
1201
let block = blocks[ drop_idx] . unwrap ( ) ;
1218
1202
let stmt = Statement {
1219
- source_info : source_info ( drop_data. 0 . span ) ,
1203
+ source_info : drop_data. 0 . source_info ,
1220
1204
kind : StatementKind :: StorageDead ( drop_data. 0 . local ) ,
1221
1205
} ;
1222
1206
cfg. push ( block, stmt) ;
1223
1207
let target = blocks[ drop_data. 1 ] . unwrap ( ) ;
1224
1208
if target != block {
1225
1209
let terminator = TerminatorKind :: Goto { target } ;
1226
- cfg. terminate ( block, source_info ( drop_data. 0 . span ) , terminator) ;
1210
+ cfg. terminate ( block, drop_data. 0 . source_info , terminator) ;
1227
1211
}
1228
1212
}
1229
1213
}
0 commit comments