Skip to content

Commit

Permalink
Kill borrows from assignments after generating new borrows
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Aug 31, 2019
1 parent b314654 commit c621919
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/librustc_mir/dataflow/impls/borrows.rs
Expand Up @@ -269,10 +269,6 @@ impl<'a, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'tcx> {
debug!("Borrows::statement_effect: stmt={:?}", stmt);
match stmt.kind {
mir::StatementKind::Assign(ref lhs, ref rhs) => {
// Make sure there are no remaining borrows for variables
// that are assigned over.
self.kill_borrows_on_place(trans, lhs);

if let mir::Rvalue::Ref(_, _, ref place) = **rhs {
if place.ignore_borrow(
self.tcx,
Expand All @@ -287,6 +283,10 @@ impl<'a, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'tcx> {

trans.gen(*index);
}

// Make sure there are no remaining borrows for variables
// that are assigned over.
self.kill_borrows_on_place(trans, lhs);
}

mir::StatementKind::StorageDead(local) => {
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/nll/self-assign-ref-mut.rs
@@ -0,0 +1,20 @@
// Check that `*y` isn't borrowed after `y = y`.

// check-pass

fn main() {
let mut x = 1;
{
let mut y = &mut x;
y = y;
y;
}
x;
{
let mut y = &mut x;
y = y;
y = y;
y;
}
x;
}

0 comments on commit c621919

Please sign in to comment.