Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure separate activations only occur for assignments to locals #46887

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
}
}

mir::StatementKind::Assign(_, ref rhs) => {
mir::StatementKind::Assign(ref lhs, ref rhs) => {
// NOTE: if/when the Assign case is revised to inspect
// the assigned_place here, make sure to also
// re-consider the current implementations of the
Expand All @@ -382,6 +382,22 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
panic!("could not find BorrowIndexs for region {:?}", region);
}).contains(&index));
sets.gen(&ReserveOrActivateIndex::reserved(*index));

if is_activations {
// Issue #46746: Two-phase borrows handles
// stmts of form `Tmp = &mut Borrow` ...
match lhs {
Place::Local(..) => {} // okay
Place::Static(..) => unreachable!(), // (filtered by is_unsafe_place)
Place::Projection(..) => {
// ... can assign into projections,
// e.g. `box (&mut _)`. Current
// conservative solution: force
// immediate activation here.
sets.gen(&ReserveOrActivateIndex::active(*index));
}
}
}
}
}

Expand Down