Skip to content

Commit aea61e3

Browse files
committed
converting a VisitorValue to a MemPlace must not mutate anything
1 parent 77c2834 commit aea61e3

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/librustc_mir/interpret/visitor.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ pub trait Value<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>>: Copy
2222
fn layout(&self) -> TyLayout<'tcx>;
2323

2424
// Make this a `MPlaceTy`, or panic if that's not possible.
25-
fn force_allocation(
25+
fn to_mem_place(
2626
self,
27-
ectx: &mut EvalContext<'a, 'mir, 'tcx, M>,
27+
ectx: &EvalContext<'a, 'mir, 'tcx, M>,
2828
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>>;
2929

3030
// Create this from an `MPlaceTy`.
@@ -55,9 +55,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
5555
}
5656

5757
#[inline(always)]
58-
fn force_allocation(
58+
fn to_mem_place(
5959
self,
60-
_ectx: &mut EvalContext<'a, 'mir, 'tcx, M>,
60+
_ectx: &EvalContext<'a, 'mir, 'tcx, M>,
6161
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
6262
Ok(self.to_mem_place())
6363
}
@@ -94,9 +94,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
9494
}
9595

9696
#[inline(always)]
97-
fn force_allocation(
97+
fn to_mem_place(
9898
self,
99-
_ectx: &mut EvalContext<'a, 'mir, 'tcx, M>,
99+
_ectx: &EvalContext<'a, 'mir, 'tcx, M>,
100100
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
101101
Ok(self)
102102
}
@@ -133,11 +133,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Value<'a, 'mir, 'tcx, M>
133133
}
134134

135135
#[inline(always)]
136-
fn force_allocation(
136+
fn to_mem_place(
137137
self,
138-
ectx: &mut EvalContext<'a, 'mir, 'tcx, M>,
138+
ectx: &EvalContext<'a, 'mir, 'tcx, M>,
139139
) -> EvalResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
140-
ectx.force_allocation(self)
140+
// If this refers to a local, assert that it already has an allocation.
141+
Ok(ectx.place_to_op(self)?.to_mem_place())
141142
}
142143

143144
#[inline(always)]
@@ -243,7 +244,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
243244
match v.layout().ty.sty {
244245
ty::Dynamic(..) => {
245246
// immediate trait objects are not a thing
246-
let dest = v.value().force_allocation(self)?;
247+
let dest = v.value().to_mem_place(self)?;
247248
let inner = self.unpack_dyn_trait(dest)?.1;
248249
trace!("dyn object layout: {:#?}", inner.layout);
249250
// recurse with the inner type
@@ -310,7 +311,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
310311
MPlaceTy::dangling(v.layout(), self)
311312
} else {
312313
// non-ZST array/slice/str cannot be immediate
313-
v.value().force_allocation(self)?
314+
v.value().to_mem_place(self)?
314315
};
315316
// Now iterate over it.
316317
for (i, field) in self.mplace_array_fields(mplace)?.enumerate() {

0 commit comments

Comments
 (0)