+
+impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
+ /// A helper function that allocates memory for the layout given and gives you access to mutate
+ /// it. Once your own mutation code is done, the backing `Allocation` is removed from the
+ /// current `Memory` and returned.
+ pub(crate) fn with_temp_alloc(
+ &mut self,
+ layout: TyAndLayout<'tcx>,
+ f: impl FnOnce(
+ &mut InterpCx<'mir, 'tcx, M>,
+ MPlaceTy<'tcx, M::PointerTag>,
+ ) -> InterpResult<'tcx, ()>,
+ ) -> InterpResult<'tcx, &'tcx Allocation> {
+ let dest = self.allocate(layout, MemoryKind::Stack);
+ f(self, dest)?;
+ let ptr = dest.ptr.assert_ptr();
+ assert_eq!(ptr.offset, Size::ZERO);
+ let mut alloc = self.memory.alloc_map.remove(&ptr.alloc_id).unwrap().1;
+ alloc.mutability = Mutability::Not;
+ Ok(self.tcx.intern_const_alloc(alloc))
+ }
+}