@@ -34,13 +34,13 @@ use crate::expr_use_visitor;
34
34
/// record the parent expression, which is the point where the drop actually takes place.
35
35
pub struct ExprUseDelegate < ' tcx > {
36
36
hir : Map < ' tcx > ,
37
- /// Records the point at which an expression or local variable is dropped .
37
+ /// Records the variables/expressions that are dropped by a given expression .
38
38
///
39
39
/// The key is the hir-id of the expression, and the value is a set or hir-ids for variables
40
40
/// or values that are consumed by that expression.
41
41
///
42
42
/// Note that this set excludes "partial drops" -- for example, a statement like `drop(x.y)` is
43
- /// not considered a drop of `x`.
43
+ /// not considered a drop of `x`, although it would be a drop of `x.y` .
44
44
consumed_places : HirIdMap < HirIdSet > ,
45
45
/// A set of hir-ids of values or variables that are borrowed at some point within the body.
46
46
borrowed_places : HirIdSet ,
@@ -437,29 +437,29 @@ impl DropRanges {
437
437
let mut changed = false ;
438
438
for id in self . nodes . indices ( ) {
439
439
let old_state = self . nodes [ id] . drop_state . clone ( ) ;
440
- if preds[ id] . len ( ) != 0 {
441
- self . nodes [ id] . drop_state = self . nodes [ preds[ id] [ 0 ] ] . drop_state . clone ( ) ;
442
- for pred in & preds[ id] [ 1 ..] {
443
- let state = self . nodes [ * pred] . drop_state . clone ( ) ;
444
- self . nodes [ id] . drop_state . intersect ( & state) ;
445
- }
440
+ let mut new_state = if id. index ( ) == 0 {
441
+ BitSet :: new_empty ( self . num_values ( ) )
446
442
} else {
447
- self . nodes [ id] . drop_state = if id. index ( ) == 0 {
448
- BitSet :: new_empty ( self . num_values ( ) )
449
- } else {
450
- // If we are not the start node and we have no predecessors, treat
451
- // everything as dropped because there's no way to get here anyway.
452
- BitSet :: new_filled ( self . num_values ( ) )
453
- } ;
443
+ // If we are not the start node and we have no predecessors, treat
444
+ // everything as dropped because there's no way to get here anyway.
445
+ BitSet :: new_filled ( self . num_values ( ) )
454
446
} ;
455
- for drop in & self . nodes [ id] . drops . clone ( ) {
456
- self . nodes [ id] . drop_state . insert ( * drop) ;
447
+
448
+ for pred in & preds[ id] {
449
+ let state = & self . nodes [ * pred] . drop_state ;
450
+ new_state. intersect ( state) ;
451
+ }
452
+
453
+ for drop in & self . nodes [ id] . drops {
454
+ new_state. insert ( * drop) ;
457
455
}
458
- for reinit in & self . nodes [ id] . reinits . clone ( ) {
459
- self . nodes [ id] . drop_state . remove ( * reinit) ;
456
+
457
+ for reinit in & self . nodes [ id] . reinits {
458
+ new_state. remove ( * reinit) ;
460
459
}
461
460
462
- changed |= old_state != self . nodes [ id] . drop_state ;
461
+ changed |= old_state != new_state;
462
+ self . nodes [ id] . drop_state = new_state;
463
463
}
464
464
465
465
changed
@@ -476,7 +476,7 @@ impl DropRanges {
476
476
let mut preds = IndexVec :: from_fn_n ( |_| vec ! [ ] , self . nodes . len ( ) ) ;
477
477
for ( id, node) in self . nodes . iter_enumerated ( ) {
478
478
if node. successors . len ( ) == 0 && id. index ( ) != self . nodes . len ( ) - 1 {
479
- preds[ < _ > :: from ( id . index ( ) + 1 ) ] . push ( id) ;
479
+ preds[ id + 1 ] . push ( id) ;
480
480
} else {
481
481
for succ in & node. successors {
482
482
preds[ * succ] . push ( id) ;
@@ -501,7 +501,7 @@ impl<'a> dot::GraphWalk<'a> for DropRanges {
501
501
. iter_enumerated ( )
502
502
. flat_map ( |( i, node) | {
503
503
if node. successors . len ( ) == 0 {
504
- vec ! [ ( i, PostOrderId :: from_usize ( i . index ( ) + 1 ) ) ]
504
+ vec ! [ ( i, i + 1 ) ]
505
505
} else {
506
506
node. successors . iter ( ) . map ( move |& s| ( i, s) ) . collect ( )
507
507
}
0 commit comments