@@ -238,6 +238,9 @@ trait DropTreeBuilder<'tcx> {
238238
239239impl DropTree {
240240 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.
241244 let fake_source_info = SourceInfo :: outermost ( DUMMY_SP ) ;
242245 let fake_data =
243246 DropData { source_info : fake_source_info, local : Local :: MAX , kind : DropKind :: Storage } ;
@@ -259,6 +262,10 @@ impl DropTree {
259262 self . entry_points . push ( ( to, from) ) ;
260263 }
261264
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.
262269 fn build_mir < ' tcx , T : DropTreeBuilder < ' tcx > > (
263270 & mut self ,
264271 cfg : & mut CFG < ' tcx > ,
@@ -1345,10 +1352,16 @@ impl<'tcx> DropTreeBuilder<'tcx> for GeneratorDrop {
13451352 cfg. start_new_block ( )
13461353 }
13471354 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 {
13501357 * 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+ }
13521365 }
13531366}
13541367
@@ -1359,8 +1372,8 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
13591372 cfg. start_new_cleanup_block ( )
13601373 }
13611374 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 {
13641377 TerminatorKind :: Drop { unwind, .. }
13651378 | TerminatorKind :: DropAndReplace { unwind, .. }
13661379 | TerminatorKind :: FalseUnwind { unwind, .. }
@@ -1376,7 +1389,9 @@ impl<'tcx> DropTreeBuilder<'tcx> for Unwind {
13761389 | TerminatorKind :: Unreachable
13771390 | TerminatorKind :: Yield { .. }
13781391 | 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+ }
13801395 }
13811396 }
13821397}
0 commit comments