Skip to content

Commit a0e1d50

Browse files
committed
Ensure separate activations only occur for assignments to locals, not projections.
Fix #46746.
1 parent b39c4bc commit a0e1d50

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/librustc_mir/dataflow/impls/borrows.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
361361
}
362362
}
363363

364-
mir::StatementKind::Assign(_, ref rhs) => {
364+
mir::StatementKind::Assign(ref lhs, ref rhs) => {
365365
// NOTE: if/when the Assign case is revised to inspect
366366
// the assigned_place here, make sure to also
367367
// re-consider the current implementations of the
@@ -382,6 +382,22 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
382382
panic!("could not find BorrowIndexs for region {:?}", region);
383383
}).contains(&index));
384384
sets.gen(&ReserveOrActivateIndex::reserved(*index));
385+
386+
if is_activations {
387+
// Issue #46746: Two-phase borrows handles
388+
// stmts of form `Tmp = &mut Borrow` ...
389+
match lhs {
390+
Place::Local(..) => {} // okay
391+
Place::Static(..) => unreachable!(), // (filtered by is_unsafe_place)
392+
Place::Projection(..) => {
393+
// ... can assign into projections,
394+
// e.g. `box (&mut _)`. Current
395+
// conservative solution: force
396+
// immediate activation here.
397+
sets.gen(&ReserveOrActivateIndex::active(*index));
398+
}
399+
}
400+
}
385401
}
386402
}
387403

0 commit comments

Comments
 (0)