mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
Kill borrows from assignments after generating new borrows
This commit is contained in:
parent
b3146549ab
commit
c621919deb
@ -269,10 +269,6 @@ impl<'a, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'tcx> {
|
|||||||
debug!("Borrows::statement_effect: stmt={:?}", stmt);
|
debug!("Borrows::statement_effect: stmt={:?}", stmt);
|
||||||
match stmt.kind {
|
match stmt.kind {
|
||||||
mir::StatementKind::Assign(ref lhs, ref rhs) => {
|
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 let mir::Rvalue::Ref(_, _, ref place) = **rhs {
|
||||||
if place.ignore_borrow(
|
if place.ignore_borrow(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
@ -287,6 +283,10 @@ impl<'a, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'tcx> {
|
|||||||
|
|
||||||
trans.gen(*index);
|
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) => {
|
mir::StatementKind::StorageDead(local) => {
|
||||||
|
20
src/test/ui/nll/self-assign-ref-mut.rs
Normal file
20
src/test/ui/nll/self-assign-ref-mut.rs
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user