diff options
| author | bors <bors@rust-lang.org> | 2019-09-01 08:15:04 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-09-01 08:15:04 +0000 |
| commit | d0677b9abc143d64d6b0cd6720e36eb73674632f (patch) | |
| tree | 9151276a5d22c4fddaad40a88a6f6b5777793d74 /src | |
| parent | 59cc53e6e708e9b9e86822c1b4d69f28f6c45eae (diff) | |
| parent | c621919deb00448e2287213a0d0bc65ff382af66 (diff) | |
| download | rust-d0677b9abc143d64d6b0cd6720e36eb73674632f.tar.gz rust-d0677b9abc143d64d6b0cd6720e36eb73674632f.zip | |
Auto merge of #64036 - matthewjasper:kill-borrows-on-self-assign, r=estebank
Kill borrows from assignments after generating new borrows Closes #63719
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/dataflow/impls/borrows.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/nll/self-assign-ref-mut.rs | 20 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index 018fd2e97b2..2ea6c4ae10f 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -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) => { diff --git a/src/test/ui/nll/self-assign-ref-mut.rs b/src/test/ui/nll/self-assign-ref-mut.rs new file mode 100644 index 00000000000..1ca4cf3a775 --- /dev/null +++ b/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; +} |
