Use a RefCell in MaybeRequiresStorage.

This will let us make `Analysis` arguments in many other places
immutable, in the next commit.
This commit is contained in:
Nicholas Nethercote 2025-10-27 16:04:02 +11:00
parent 517b767fa1
commit 8afbd9fe02

View file

@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::cell::RefCell;
use rustc_index::bit_set::DenseBitSet;
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
@ -115,12 +116,12 @@ type BorrowedLocalsResults<'mir, 'tcx> = ResultsCursor<'mir, 'tcx, MaybeBorrowed
/// Dataflow analysis that determines whether each local requires storage at a
/// given location; i.e. whether its storage can go away without being observed.
pub struct MaybeRequiresStorage<'mir, 'tcx> {
borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>,
borrowed_locals: RefCell<BorrowedLocalsResults<'mir, 'tcx>>,
}
impl<'mir, 'tcx> MaybeRequiresStorage<'mir, 'tcx> {
pub fn new(borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>) -> Self {
MaybeRequiresStorage { borrowed_locals }
MaybeRequiresStorage { borrowed_locals: RefCell::new(borrowed_locals) }
}
}
@ -294,9 +295,10 @@ impl<'tcx> Analysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
impl<'tcx> MaybeRequiresStorage<'_, 'tcx> {
/// Kill locals that are fully moved and have not been borrowed.
fn check_for_move(&mut self, state: &mut <Self as Analysis<'tcx>>::Domain, loc: Location) {
let body = self.borrowed_locals.body();
let mut visitor = MoveVisitor { state, borrowed_locals: &mut self.borrowed_locals };
fn check_for_move(&self, state: &mut <Self as Analysis<'tcx>>::Domain, loc: Location) {
let mut borrowed_locals = self.borrowed_locals.borrow_mut();
let body = borrowed_locals.body();
let mut visitor = MoveVisitor { state, borrowed_locals: &mut borrowed_locals };
visitor.visit_location(body, loc);
}
}