@@ -134,7 +134,7 @@ struct Scope {
134
134
struct DropData {
135
135
/// The `Span` where drop obligation was incurred (typically where place was
136
136
/// declared)
137
- span : Span ,
137
+ source_info : SourceInfo ,
138
138
139
139
/// local to drop
140
140
local : Local ,
@@ -179,8 +179,7 @@ const CONTINUE_NODE: DropIdx = DropIdx::from_u32_const(1);
179
179
// TODO say some more.
180
180
#[ derive( Debug ) ]
181
181
struct DropTree {
182
- /// The next item to drop, if there is one.
183
- // TODO actual comment
182
+ /// Drops in the tree.
184
183
drops : IndexVec < DropIdx , ( DropData , DropIdx ) > ,
185
184
/// Map for finding the inverse of the `next_drop` relation:
186
185
///
@@ -193,11 +192,6 @@ struct DropTree {
193
192
}
194
193
195
194
impl Scope {
196
- /// Given a span and this scope's source scope, make a SourceInfo.
197
- fn source_info ( & self , span : Span ) -> SourceInfo {
198
- SourceInfo { span, scope : self . source_scope }
199
- }
200
-
201
195
/// Whether there's anything to do for the cleanup path, that is,
202
196
/// when unwinding through this scope. This includes destructors,
203
197
/// but not StorageDead statements, which don't get emitted at all
@@ -219,7 +213,9 @@ impl Scope {
219
213
220
214
impl DropTree {
221
215
fn new ( num_roots : usize ) -> Self {
222
- let fake_data = DropData { span : DUMMY_SP , local : Local :: MAX , kind : DropKind :: Storage } ;
216
+ let fake_source_info = SourceInfo { span : DUMMY_SP , scope : OUTERMOST_SOURCE_SCOPE } ;
217
+ let fake_data =
218
+ DropData { source_info : fake_source_info, local : Local :: MAX , kind : DropKind :: Storage } ;
223
219
let drop_idx = DropIdx :: MAX ;
224
220
let drops = IndexVec :: from_elem_n ( ( fake_data, drop_idx) , num_roots) ;
225
221
Self {
@@ -286,10 +282,6 @@ impl<'tcx> Scopes<'tcx> {
286
282
fn topmost ( & self ) -> region:: Scope {
287
283
self . scopes . last ( ) . expect ( "topmost_scope: no scopes present" ) . region_scope
288
284
}
289
-
290
- // fn source_info(&self, index: usize, span: Span) -> SourceInfo {
291
- // self.scopes[self.len() - index].source_info(span)
292
- // }
293
285
}
294
286
295
287
impl < ' a , ' tcx > Builder < ' a , ' tcx > {
@@ -497,7 +489,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
497
489
self . cfg . start_new_block ( ) . unit ( )
498
490
}
499
491
500
- // TODO: use in pop_top_scope.
501
492
crate fn exit_top_scope (
502
493
& mut self ,
503
494
mut block : BasicBlock ,
@@ -685,7 +676,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
685
676
// Attribute scope exit drops to scope's closing brace.
686
677
let scope_end = self . hir . tcx ( ) . sess . source_map ( ) . end_point ( region_scope_span) ;
687
678
688
- scope. drops . push ( DropData { span : scope_end, local, kind : drop_kind } ) ;
679
+ scope. drops . push ( DropData {
680
+ source_info : SourceInfo { span : scope_end, scope : scope. source_scope } ,
681
+ local,
682
+ kind : drop_kind,
683
+ } ) ;
689
684
}
690
685
691
686
/// Indicates that the "local operand" stored in `local` is
@@ -790,7 +785,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
790
785
bug ! ( "Drop scheduled on top of condition variable" )
791
786
}
792
787
DropKind :: Storage => {
793
- let source_info = top_scope . source_info ( top_drop_data. span ) ;
788
+ let source_info = top_drop_data. source_info ;
794
789
let local = top_drop_data. local ;
795
790
assert_eq ! ( local, cond_temp, "Drop scheduled on top of condition" ) ;
796
791
self . cfg . push (
@@ -928,7 +923,7 @@ fn build_scope_drops<'tcx>(
928
923
// `diverge_cleanup_gen`.
929
924
930
925
for drop_data in scope. drops . iter ( ) . rev ( ) {
931
- let source_info = scope . source_info ( drop_data. span ) ;
926
+ let source_info = drop_data. source_info ;
932
927
let local = drop_data. local ;
933
928
934
929
match drop_data. kind {
@@ -1097,10 +1092,6 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
1097
1092
}
1098
1093
}
1099
1094
1100
- fn source_info ( span : Span ) -> SourceInfo {
1101
- SourceInfo { span, scope : OUTERMOST_SOURCE_SCOPE }
1102
- }
1103
-
1104
1095
fn build_drop_tree < ' tcx , T : DropTreeBuilder < ' tcx > > (
1105
1096
cfg : & mut CFG < ' tcx > ,
1106
1097
drops : & mut DropTree ,
@@ -1172,21 +1163,21 @@ fn build_drop_tree<'tcx, T: DropTreeBuilder<'tcx>>(
1172
1163
unwind : None ,
1173
1164
location : drop_data. 0 . local . into ( ) ,
1174
1165
} ;
1175
- cfg. terminate ( blocks[ drop_idx] . unwrap ( ) , source_info ( drop_data. 0 . span ) , terminator) ;
1166
+ cfg. terminate ( blocks[ drop_idx] . unwrap ( ) , drop_data. 0 . source_info , terminator) ;
1176
1167
}
1177
1168
// Root nodes don't correspond to a drop.
1178
1169
DropKind :: Storage if drop_idx < drops. num_roots => { }
1179
1170
DropKind :: Storage => {
1180
1171
let block = blocks[ drop_idx] . unwrap ( ) ;
1181
1172
let stmt = Statement {
1182
- source_info : source_info ( drop_data. 0 . span ) ,
1173
+ source_info : drop_data. 0 . source_info ,
1183
1174
kind : StatementKind :: StorageDead ( drop_data. 0 . local ) ,
1184
1175
} ;
1185
1176
cfg. push ( block, stmt) ;
1186
1177
let target = blocks[ drop_data. 1 ] . unwrap ( ) ;
1187
1178
if target != block {
1188
1179
let terminator = TerminatorKind :: Goto { target } ;
1189
- cfg. terminate ( block, source_info ( drop_data. 0 . span ) , terminator) ;
1180
+ cfg. terminate ( block, drop_data. 0 . source_info , terminator) ;
1190
1181
}
1191
1182
}
1192
1183
}
0 commit comments