@@ -305,27 +305,25 @@ impl DropTree {
305
305
}
306
306
307
307
/// Builds the MIR for a given drop tree.
308
- ///
309
- /// `blocks` should have the same length as `self.drops`, and may have its
310
- /// first value set to some already existing block.
311
308
fn build_mir < ' tcx , T : DropTreeBuilder < ' tcx > > (
312
309
& mut self ,
313
310
cfg : & mut CFG < ' tcx > ,
314
- blocks : & mut IndexVec < DropIdx , Option < BasicBlock > > ,
315
- ) {
311
+ root_node : Option < BasicBlock > ,
312
+ ) -> IndexVec < DropIdx , Option < BasicBlock > > {
316
313
debug ! ( "DropTree::build_mir(drops = {:#?})" , self ) ;
317
- assert_eq ! ( blocks. len( ) , self . drops. len( ) ) ;
318
314
319
- self . assign_blocks :: < T > ( cfg, blocks) ;
320
- self . link_blocks ( cfg, blocks)
315
+ let mut blocks = self . assign_blocks :: < T > ( cfg, root_node) ;
316
+ self . link_blocks ( cfg, & mut blocks) ;
317
+
318
+ blocks
321
319
}
322
320
323
321
/// Assign blocks for all of the drops in the drop tree that need them.
324
322
fn assign_blocks < ' tcx , T : DropTreeBuilder < ' tcx > > (
325
323
& mut self ,
326
324
cfg : & mut CFG < ' tcx > ,
327
- blocks : & mut IndexVec < DropIdx , Option < BasicBlock > > ,
328
- ) {
325
+ root_node : Option < BasicBlock > ,
326
+ ) -> IndexVec < DropIdx , Option < BasicBlock > > {
329
327
// StorageDead statements can share blocks with each other and also with
330
328
// a Drop terminator. We iterate through the drops to find which drops
331
329
// need their own block.
@@ -342,8 +340,11 @@ impl DropTree {
342
340
Own ,
343
341
}
344
342
343
+ let mut blocks = IndexVec :: from_elem ( None , & self . drops ) ;
344
+ blocks[ ROOT_NODE ] = root_node;
345
+
345
346
let mut needs_block = IndexVec :: from_elem ( Block :: None , & self . drops ) ;
346
- if blocks [ ROOT_NODE ] . is_some ( ) {
347
+ if root_node . is_some ( ) {
347
348
// In some cases (such as drops for `continue`) the root node
348
349
// already has a block. In this case, make sure that we don't
349
350
// override it.
@@ -385,6 +386,8 @@ impl DropTree {
385
386
386
387
debug ! ( "assign_blocks: blocks = {:#?}" , blocks) ;
387
388
assert ! ( entry_points. is_empty( ) ) ;
389
+
390
+ blocks
388
391
}
389
392
390
393
fn link_blocks < ' tcx > (
@@ -1574,10 +1577,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
1574
1577
span : Span ,
1575
1578
continue_block : Option < BasicBlock > ,
1576
1579
) -> Option < BlockAnd < ( ) > > {
1577
- let mut blocks = IndexVec :: from_elem ( None , & drops. drops ) ;
1578
- blocks[ ROOT_NODE ] = continue_block;
1579
-
1580
- drops. build_mir :: < ExitScopes > ( & mut self . cfg , & mut blocks) ;
1580
+ let blocks = drops. build_mir :: < ExitScopes > ( & mut self . cfg , continue_block) ;
1581
1581
let is_coroutine = self . coroutine . is_some ( ) ;
1582
1582
1583
1583
// Link the exit drop tree to unwind drop tree.
@@ -1633,8 +1633,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
1633
1633
let drops = & mut self . scopes . coroutine_drops ;
1634
1634
let cfg = & mut self . cfg ;
1635
1635
let fn_span = self . fn_span ;
1636
- let mut blocks = IndexVec :: from_elem ( None , & drops. drops ) ;
1637
- drops. build_mir :: < CoroutineDrop > ( cfg, & mut blocks) ;
1636
+ let blocks = drops. build_mir :: < CoroutineDrop > ( cfg, None ) ;
1638
1637
if let Some ( root_block) = blocks[ ROOT_NODE ] {
1639
1638
cfg. terminate (
1640
1639
root_block,
@@ -1670,9 +1669,7 @@ impl<'a, 'tcx: 'a> Builder<'a, 'tcx> {
1670
1669
fn_span : Span ,
1671
1670
resume_block : & mut Option < BasicBlock > ,
1672
1671
) {
1673
- let mut blocks = IndexVec :: from_elem ( None , & drops. drops ) ;
1674
- blocks[ ROOT_NODE ] = * resume_block;
1675
- drops. build_mir :: < Unwind > ( cfg, & mut blocks) ;
1672
+ let blocks = drops. build_mir :: < Unwind > ( cfg, * resume_block) ;
1676
1673
if let ( None , Some ( resume) ) = ( * resume_block, blocks[ ROOT_NODE ] ) {
1677
1674
cfg. terminate ( resume, SourceInfo :: outermost ( fn_span) , TerminatorKind :: UnwindResume ) ;
1678
1675
0 commit comments