Auto merge of #64036 - matthewjasper:kill-borrows-on-self-assign, r=estebank

Kill borrows from assignments after generating new borrows

Closes #63719
This commit is contained in:
bors 2019-09-01 08:15:04 +00:00
commit d0677b9abc
2 changed files with 24 additions and 4 deletions

View File

@ -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,
@ -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) => {

View File

@ -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;
}