@@ -238,6 +238,9 @@ trait DropTreeBuilder<'tcx> {
238
238
239
239
impl DropTree {
240
240
fn new ( ) -> Self {
241
+ // The root node of the tree doesn't represent a drop, but instead
242
+ // represents the block in the tree that should be jumped to once all
243
+ // of the required drops have been performed.
241
244
let fake_source_info = SourceInfo :: outermost ( DUMMY_SP ) ;
242
245
let fake_data =
243
246
DropData { source_info : fake_source_info, local : Local :: MAX , kind : DropKind :: Storage } ;
@@ -259,6 +262,10 @@ impl DropTree {
259
262
self . entry_points . push ( ( to, from) ) ;
260
263
}
261
264
265
+ /// Builds the MIR for a given drop tree.
266
+ ///
267
+ /// `blocks` should have the same length as `self.drops`, and may have its
268
+ /// first value set to some already existing block.
262
269
fn build_mir < ' tcx , T : DropTreeBuilder < ' tcx > > (
263
270
& mut self ,
264
271
cfg : & mut CFG < ' tcx > ,
@@ -1345,10 +1352,16 @@ impl<'tcx> DropTreeBuilder<'tcx> for GeneratorDrop {
1345
1352
cfg. start_new_block ( )
1346
1353
}
1347
1354
fn add_entry ( cfg : & mut CFG < ' tcx > , from : BasicBlock , to : BasicBlock ) {
1348
- let kind = & mut cfg. block_data_mut ( from) . terminator_mut ( ) . kind ;
1349
- if let TerminatorKind :: Yield { drop, .. } = kind {
1355
+ let term = cfg. block_data_mut ( from) . terminator_mut ( ) ;
1356
+ if let TerminatorKind :: Yield { ref mut drop, .. } = term . kind {
1350
1357
* drop = Some ( to) ;
1351
- } ;
1358
+ } else {
1359
+ span_bug ! (
1360
+ term. source_info. span,
1361
+ "cannot enter generator drop tree from {:?}" ,
1362
+ term. kind
1363
+ )
1364
+ }
1352
1365
}
1353
1366
}
1354
1367
@@ -1359,8 +1372,8 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
1359
1372
cfg. start_new_cleanup_block ( )
1360
1373
}
1361
1374
fn add_entry ( cfg : & mut CFG < ' tcx > , from : BasicBlock , to : BasicBlock ) {
1362
- let term = & mut cfg. block_data_mut ( from) . terminator_mut ( ) . kind ;
1363
- match term {
1375
+ let term = & mut cfg. block_data_mut ( from) . terminator_mut ( ) ;
1376
+ match & mut term. kind {
1364
1377
TerminatorKind :: Drop { unwind, .. }
1365
1378
| TerminatorKind :: DropAndReplace { unwind, .. }
1366
1379
| TerminatorKind :: FalseUnwind { unwind, .. }
@@ -1376,7 +1389,9 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
1376
1389
| TerminatorKind :: Unreachable
1377
1390
| TerminatorKind :: Yield { .. }
1378
1391
| TerminatorKind :: GeneratorDrop
1379
- | TerminatorKind :: FalseEdges { .. } => bug ! ( "cannot unwind from {:?}" , term) ,
1392
+ | TerminatorKind :: FalseEdges { .. } => {
1393
+ span_bug ! ( term. source_info. span, "cannot unwind from {:?}" , term. kind)
1394
+ }
1380
1395
}
1381
1396
}
1382
1397
}
0 commit comments