@@ -15,9 +15,9 @@ use rustc::mir::visit::Visitor;
15
15
use dataflow:: BitDenotation ;
16
16
17
17
/// This calculates if any part of a MIR local could have previously been borrowed.
18
- /// This means that once a local has been borrowed, its bit will always be set
19
- /// from that point and onwards, even if the borrow ends. You could also think of this
20
- /// as computing the lifetimes of infinite borrows .
18
+ /// This means that once a local has been borrowed, its bit will be set
19
+ /// from that point and onwards, until we see a StorageDead statement for the local,
20
+ /// at which points there is no memory associated with the local, so it cannot be borrowed .
21
21
/// This is used to compute which locals are live during a yield expression for
22
22
/// immovable generators.
23
23
#[ derive( Copy , Clone ) ]
@@ -50,9 +50,17 @@ impl<'a, 'tcx> BitDenotation for HaveBeenBorrowedLocals<'a, 'tcx> {
50
50
fn statement_effect ( & self ,
51
51
sets : & mut BlockSets < Local > ,
52
52
loc : Location ) {
53
+ let stmt = & self . mir [ loc. block ] . statements [ loc. statement_index ] ;
54
+
53
55
BorrowedLocalsVisitor {
54
56
sets,
55
- } . visit_statement ( loc. block , & self . mir [ loc. block ] . statements [ loc. statement_index ] , loc) ;
57
+ } . visit_statement ( loc. block , stmt, loc) ;
58
+
59
+ // StorageDead invalidates all borrows and raw pointers to a local
60
+ match stmt. kind {
61
+ StatementKind :: StorageDead ( l) => sets. kill ( & l) ,
62
+ _ => ( ) ,
63
+ }
56
64
}
57
65
58
66
fn terminator_effect ( & self ,
0 commit comments