@@ -15,9 +15,9 @@ use rustc::mir::visit::Visitor;
1515use dataflow:: BitDenotation ;
1616
1717/// 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 .
2121/// This is used to compute which locals are live during a yield expression for
2222/// immovable generators.
2323#[ derive( Copy , Clone ) ]
@@ -50,9 +50,17 @@ impl<'a, 'tcx> BitDenotation for HaveBeenBorrowedLocals<'a, 'tcx> {
5050 fn statement_effect ( & self ,
5151 sets : & mut BlockSets < Local > ,
5252 loc : Location ) {
53+ let stmt = & self . mir [ loc. block ] . statements [ loc. statement_index ] ;
54+
5355 BorrowedLocalsVisitor {
5456 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+ }
5664 }
5765
5866 fn terminator_effect ( & self ,
0 commit comments