Skip to content

Commit 8afbd9f

Browse files
committed
Use a RefCell in MaybeRequiresStorage.
This will let us make `Analysis` arguments in many other places immutable, in the next commit.
1 parent 517b767 commit 8afbd9f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::borrow::Cow;
2+
use std::cell::RefCell;
23

34
use rustc_index::bit_set::DenseBitSet;
45
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
@@ -115,12 +116,12 @@ type BorrowedLocalsResults<'mir, 'tcx> = ResultsCursor<'mir, 'tcx, MaybeBorrowed
115116
/// Dataflow analysis that determines whether each local requires storage at a
116117
/// given location; i.e. whether its storage can go away without being observed.
117118
pub struct MaybeRequiresStorage<'mir, 'tcx> {
118-
borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>,
119+
borrowed_locals: RefCell<BorrowedLocalsResults<'mir, 'tcx>>,
119120
}
120121

121122
impl<'mir, 'tcx> MaybeRequiresStorage<'mir, 'tcx> {
122123
pub fn new(borrowed_locals: BorrowedLocalsResults<'mir, 'tcx>) -> Self {
123-
MaybeRequiresStorage { borrowed_locals }
124+
MaybeRequiresStorage { borrowed_locals: RefCell::new(borrowed_locals) }
124125
}
125126
}
126127

@@ -294,9 +295,10 @@ impl<'tcx> Analysis<'tcx> for MaybeRequiresStorage<'_, 'tcx> {
294295

295296
impl<'tcx> MaybeRequiresStorage<'_, 'tcx> {
296297
/// Kill locals that are fully moved and have not been borrowed.
297-
fn check_for_move(&mut self, state: &mut <Self as Analysis<'tcx>>::Domain, loc: Location) {
298-
let body = self.borrowed_locals.body();
299-
let mut visitor = MoveVisitor { state, borrowed_locals: &mut self.borrowed_locals };
298+
fn check_for_move(&self, state: &mut <Self as Analysis<'tcx>>::Domain, loc: Location) {
299+
let mut borrowed_locals = self.borrowed_locals.borrow_mut();
300+
let body = borrowed_locals.body();
301+
let mut visitor = MoveVisitor { state, borrowed_locals: &mut borrowed_locals };
300302
visitor.visit_location(body, loc);
301303
}
302304
}

0 commit comments

Comments
 (0)