Struct creusot_contracts::ghost::GhostBox
source · pub struct GhostBox<T>(/* private fields */)
where
T: ?Sized;
Expand description
A type that can be used in ghost
context.
This type may be used to make more complicated proofs possible. In particular, some proof may need a notion of non-duplicable token to carry around.
Conceptually, a GhostBox<T>
is a pointer to an item of type T
that resides in
a special “ghost” heap. This heap is inaccessible from normal code, and GhostBox
values cannot be used to influence the behavior of normal code.
This box can be dereferenced in a ghost
block:
let b: GhostBox<i32> = GhostBox::new(1);
ghost! {
let value: i32 = *b;
// use value here
}
let value: i32 = *b; // compile error !
Implementations§
source§impl<T: ?Sized> GhostBox<T>
impl<T: ?Sized> GhostBox<T>
sourcepub fn borrow(&self) -> GhostBox<&T>
pub fn borrow(&self) -> GhostBox<&T>
Transforms a &GhostBox<T>
into GhostBox<&T>
.
pure
ensures
*result.0 == &*self.0
sourcepub fn borrow_mut(&mut self) -> GhostBox<&mut T>
pub fn borrow_mut(&mut self) -> GhostBox<&mut T>
Transforms a &mut GhostBox<T>
into a GhostBox<&mut T>
.
pure
ensures
*result.0 == &mut *self.0
sourcepub fn conjure() -> Self
pub fn conjure() -> Self
Conjures a GhostBox<T>
out of thin air.
This would be unsound in verified code, hence the false
precondition.
This function is nevertheless useful to create a GhostBox
in “trusted”
contexts, when axiomatizing an API that is believed to be sound for
external reasons.
requires
false
source§impl<T> GhostBox<T>
impl<T> GhostBox<T>
sourcepub fn new(x: T) -> Self
pub fn new(x: T) -> Self
Creates a new ghost variable.
This function can only be called in ghost!
code.
pure
ensures
*result.0 == x
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Returns the inner value of the GhostBox
.
This function can only be called in ghost!
context.
pure
ensures
result == *self.0
sourcepub fn inner_logic(self) -> T
pub fn inner_logic(self) -> T
Returns the inner value of the GhostBox
.
You should prefer the dereference operator *
instead.
logic
*self.0
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for GhostBox<T>where
T: ?Sized,
impl<T> !RefUnwindSafe for GhostBox<T>
impl<T> !Send for GhostBox<T>
impl<T> !Sync for GhostBox<T>
impl<T> Unpin for GhostBox<T>where
T: ?Sized,
impl<T> !UnwindSafe for GhostBox<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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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