pub struct Ghost<T>(/* private fields */);
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 Ghost<T>
is an object of type T
that resides in a special “ghost”
heap. This heap is inaccessible from normal code, and Ghost
values cannot be used
to influence the behavior of normal code.
This box can be accessed in a ghost!
block:
let b: Ghost<i32> = Ghost::new(1);
ghost! {
let value: i32 = b.into_inner();
// use value here
}
let value: i32 = b.into_inner(); // compile error !
Implementations§
Source§impl<T> Ghost<T>
impl<T> Ghost<T>
Sourcepub fn borrow(&self) -> Ghost<&T>
pub fn borrow(&self) -> Ghost<&T>
Transforms a &Ghost<T>
into Ghost<&T>
.
pure
ensures
**result == **self
Sourcepub fn borrow_mut(&mut self) -> Ghost<&mut T>
pub fn borrow_mut(&mut self) -> Ghost<&mut T>
Transforms a &mut Ghost<T>
into a Ghost<&mut T>
.
pure
ensures
*result.inner_logic() == (*self).inner_logic()
ensures
^result.inner_logic() == (^self).inner_logic()
Sourcepub fn conjure() -> Self
pub fn conjure() -> Self
Conjures a Ghost<T>
out of thin air.
This would be unsound in verified code, hence the false
precondition.
This function is nevertheless useful to create a Ghost
in “trusted”
contexts, when axiomatizing an API that is believed to be sound for
external reasons.
pure
requires
false
Source§impl<T> Ghost<T>
impl<T> Ghost<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 == x
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Returns the inner value of the Ghost
.
This function can only be called in ghost!
context.
pure
ensures
result == *self
Sourcepub fn inner_logic(self) -> T
pub fn inner_logic(self) -> T
Returns the inner value of the Ghost
.
You should prefer the dereference operator *
instead.
logic
self.0
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Ghost<T>
impl<T> !RefUnwindSafe for Ghost<T>
impl<T> !Send for Ghost<T>
impl<T> !Sync for Ghost<T>
impl<T> !Unpin for Ghost<T>
impl<T> !UnwindSafe for Ghost<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§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