Skip to content

Commit c246a29

Browse files
committed
Rollup merge of rust-lang#55888 - RalfJung:alloc-extra, r=oli-obk
miri: for uniformity, also move memory_deallocated to AllocationExtra r? @oli-obk
2 parents 675c95c + 3c88cfe commit c246a29

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

src/librustc/mir/interpret/allocation.rs

+11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ pub trait AllocationExtra<Tag>: ::std::fmt::Debug + Default + Clone {
6565
) -> EvalResult<'tcx> {
6666
Ok(())
6767
}
68+
69+
/// Hook for performing extra checks on a memory deallocation.
70+
/// `size` will be the size of the allocation.
71+
#[inline]
72+
fn memory_deallocated(
73+
_alloc: &mut Allocation<Tag, Self>,
74+
_ptr: Pointer<Tag>,
75+
_size: Size,
76+
) -> EvalResult<'tcx> {
77+
Ok(())
78+
}
6879
}
6980

7081
impl AllocationExtra<()> for () {}

src/librustc_mir/interpret/machine.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::hash::Hash;
1717

1818
use rustc::hir::{self, def_id::DefId};
1919
use rustc::mir;
20-
use rustc::ty::{self, layout::{Size, TyLayout}, query::TyCtxtAt};
20+
use rustc::ty::{self, layout::TyLayout, query::TyCtxtAt};
2121

2222
use super::{
2323
Allocation, AllocId, EvalResult, Scalar, AllocationExtra,
@@ -174,16 +174,6 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
174174
dest: PlaceTy<'tcx, Self::PointerTag>,
175175
) -> EvalResult<'tcx>;
176176

177-
/// Hook for performing extra checks when memory gets deallocated.
178-
#[inline]
179-
fn memory_deallocated(
180-
_alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
181-
_ptr: Pointer<Self::PointerTag>,
182-
_size: Size,
183-
) -> EvalResult<'tcx> {
184-
Ok(())
185-
}
186-
187177
/// Add the tag for a newly allocated pointer.
188178
fn tag_new_allocation(
189179
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,

src/librustc_mir/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
225225

226226
// Let the machine take some extra action
227227
let size = Size::from_bytes(alloc.bytes.len() as u64);
228-
M::memory_deallocated(&mut alloc, ptr, size)?;
228+
AllocationExtra::memory_deallocated(&mut alloc, ptr, size)?;
229229

230230
// Don't forget to remember size and align of this now-dead allocation
231231
let old = self.dead_alloc_map.insert(

0 commit comments

Comments
 (0)