Skip to content

Commit d0677b9

Browse files
committed
Auto merge of #64036 - matthewjasper:kill-borrows-on-self-assign, r=estebank
Kill borrows from assignments after generating new borrows Closes #63719
2 parents 59cc53e + c621919 commit d0677b9

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/librustc_mir/dataflow/impls/borrows.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,6 @@ impl<'a, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'tcx> {
269269
debug!("Borrows::statement_effect: stmt={:?}", stmt);
270270
match stmt.kind {
271271
mir::StatementKind::Assign(ref lhs, ref rhs) => {
272-
// Make sure there are no remaining borrows for variables
273-
// that are assigned over.
274-
self.kill_borrows_on_place(trans, lhs);
275-
276272
if let mir::Rvalue::Ref(_, _, ref place) = **rhs {
277273
if place.ignore_borrow(
278274
self.tcx,
@@ -287,6 +283,10 @@ impl<'a, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'tcx> {
287283

288284
trans.gen(*index);
289285
}
286+
287+
// Make sure there are no remaining borrows for variables
288+
// that are assigned over.
289+
self.kill_borrows_on_place(trans, lhs);
290290
}
291291

292292
mir::StatementKind::StorageDead(local) => {
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Check that `*y` isn't borrowed after `y = y`.
2+
3+
// check-pass
4+
5+
fn main() {
6+
let mut x = 1;
7+
{
8+
let mut y = &mut x;
9+
y = y;
10+
y;
11+
}
12+
x;
13+
{
14+
let mut y = &mut x;
15+
y = y;
16+
y = y;
17+
y;
18+
}
19+
x;
20+
}

0 commit comments

Comments
 (0)