Skip to content

Commit 5d58a03

Browse files
committed
Give AllocationExtras access to their entire Allocation
1 parent 769ee79 commit 5d58a03

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

Diff for: src/librustc/mir/interpret/allocation.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,17 @@ pub trait AllocationExtra<Tag>: ::std::fmt::Debug + Default + Clone {
4949
/// need to mutate.
5050
#[inline]
5151
fn memory_read(
52-
&self,
52+
_alloc: &Allocation<Tag, Self>,
5353
_ptr: Pointer<Tag>,
5454
_size: Size,
5555
) -> EvalResult<'tcx> {
5656
Ok(())
5757
}
5858

5959
/// Hook for performing extra checks on a memory write access.
60-
///
61-
/// Takes read-only access to the allocation so we can keep all the memory read
62-
/// operations take `&self`. Use a `RefCell` in `AllocExtra` if you
63-
/// need to mutate.
6460
#[inline]
6561
fn memory_written(
66-
&mut self,
62+
_alloc: &mut Allocation<Tag, Self>,
6763
_ptr: Pointer<Tag>,
6864
_size: Size,
6965
) -> EvalResult<'tcx> {

Diff for: src/librustc_mir/interpret/memory.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
637637
}
638638

639639
let alloc = self.get(ptr.alloc_id)?;
640-
AllocationExtra::memory_read(&alloc.extra, ptr, size)?;
640+
AllocationExtra::memory_read(alloc, ptr, size)?;
641641

642642
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
643643
assert_eq!(size.bytes() as usize as u64, size.bytes());
@@ -683,7 +683,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
683683
self.clear_relocations(ptr, size)?;
684684

685685
let alloc = self.get_mut(ptr.alloc_id)?;
686-
AllocationExtra::memory_written(&mut alloc.extra, ptr, size)?;
686+
AllocationExtra::memory_written(alloc, ptr, size)?;
687687

688688
assert_eq!(ptr.offset.bytes() as usize as u64, ptr.offset.bytes());
689689
assert_eq!(size.bytes() as usize as u64, size.bytes());

0 commit comments

Comments
 (0)