pub struct PtrOwn<T: ?Sized> { /* private fields */ }
Expand description
Token that represents the ownership of a memory cell. A PtrOwn
value only
exists in the ghost world, but can be used in combination with a
corresponding RawPtr
to access and modify memory.
A warning regarding memory leaks: dropping a Ghost<PtrOwn<T>>
(we only
ever handle ghost PtrOwn
values) cannot deallocate the memory
corresponding to the pointer because it is a ghost value. One must thus
remember to explicitly call drop
in order to free the memory tracked by a
PtrOwn
token.
§Safety
When using Creusot to verify the code, all methods should be safe to call. Indeed,
Creusot ensures that every operation on the inner value uses the right PtrOwn
object
created by PtrOwn::new
, ensuring safety in a manner similar to ghost_cell.
Implementations§
Source§impl<T: ?Sized> PtrOwn<T>
impl<T: ?Sized> PtrOwn<T>
Sourcepub unsafe fn as_ref(ptr: RawPtr<T>, own: Ghost<&PtrOwn<T>>) -> &T
pub unsafe fn as_ref(ptr: RawPtr<T>, own: Ghost<&PtrOwn<T>>) -> &T
Immutably borrows the underlying T
.
§Safety
Safety requirements are the same as a direct dereference: &*ptr
.
Creusot will check that all calls to this function are indeed safe: see the type documentation.
requires
ptr == own.ptr()
ensures
*result == *own.val()
Sourcepub unsafe fn as_mut(ptr: RawPtr<T>, own: Ghost<&mut PtrOwn<T>>) -> &mut T
pub unsafe fn as_mut(ptr: RawPtr<T>, own: Ghost<&mut PtrOwn<T>>) -> &mut T
Mutably borrows the underlying T
.
§Safety
Safety requirements are the same as a direct dereference: &mut *ptr
.
Creusot will check that all calls to this function are indeed safe: see the type documentation.
requires
ptr == own.ptr()
ensures
*result == *own.val()
ensures
(^own.inner_logic()).ptr() == own.ptr()
ensures
*(^own.inner_logic()).val() == ^result
Sourcepub unsafe fn to_box(ptr: RawPtr<T>, own: Ghost<PtrOwn<T>>) -> Box<T>
pub unsafe fn to_box(ptr: RawPtr<T>, own: Ghost<PtrOwn<T>>) -> Box<T>
Transfers ownership of own
back into a Box
.
§Safety
Safety requirements are the same as Box::from_raw
.
Creusot will check that all calls to this function are indeed safe: see the type documentation.
requires
ptr == own.ptr()
ensures
*result == *own.val()
Sourcepub unsafe fn drop(ptr: RawPtr<T>, own: Ghost<PtrOwn<T>>)
pub unsafe fn drop(ptr: RawPtr<T>, own: Ghost<PtrOwn<T>>)
Deallocates the memory pointed by ptr
.
§Safety
Safety requirements are the same as Box::from_raw
.
Creusot will check that all calls to this function are indeed safe: see the type documentation.
requires
ptr == own.ptr()
Sourcepub fn disjoint_lemma(own1: &mut PtrOwn<T>, own2: &PtrOwn<T>)
pub fn disjoint_lemma(own1: &mut PtrOwn<T>, own2: &PtrOwn<T>)
If one owns two PtrOwn
s in ghost code, then they are for different pointers.
pure
ensures
own1.ptr().addr_logic() != own2.ptr().addr_logic()
ensures
*own1 == ^own1
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for PtrOwn<T>where
T: ?Sized,
impl<T> !RefUnwindSafe for PtrOwn<T>
impl<T> !Send for PtrOwn<T>
impl<T> !Sync for PtrOwn<T>
impl<T> Unpin for PtrOwn<T>where
T: ?Sized,
impl<T> !UnwindSafe for PtrOwn<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> MakeSized for Twhere
T: ?Sized,
impl<T> MakeSized for Twhere
T: ?Sized,
Source§fn make_sized(&self) -> Box<T>
fn make_sized(&self) -> Box<T>
logic ⚠
ensures
*result == *self