Skip to content

Commit

Permalink
Check the correct arena
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 1, 2019
1 parent 9654ae9 commit 03b8928
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/libarena/lib.rs
Expand Up @@ -119,6 +119,11 @@ impl<T> Default for TypedArena<T> {
}

impl<T> TypedArena<T> {
pub fn in_arena(&self, ptr: *const T) -> bool {
let ptr = ptr as *const T as *mut T;

self.chunks.borrow().iter().any(|chunk| chunk.start() <= ptr && ptr < chunk.end())
}
/// Allocates an object in the `TypedArena`, returning a reference to it.
#[inline]
pub fn alloc(&self, object: T) -> &mut T {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/context.rs
Expand Up @@ -1762,7 +1762,7 @@ nop_list_lift!{Kind<'a> => Kind<'tcx>}
impl<'a, 'tcx> Lift<'tcx> for &'a mir::interpret::Allocation {
type Lifted = &'tcx mir::interpret::Allocation;
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
assert!(tcx.global_interners.arena.in_arena(*self as *const _));
assert!(tcx.global_arenas.const_allocs.in_arena(*self as *const _));
Some(unsafe { mem::transmute(*self) })
}
}
Expand Down

0 comments on commit 03b8928

Please sign in to comment.