use crate::prelude::*;
mod private {
pub trait _Sealed {}
}
#[intrinsic("fn_ghost")]
pub trait FnGhost: private::_Sealed {}
#[cfg(not(creusot))]
impl<F> private::_Sealed for F {}
#[cfg(not(creusot))]
impl<F> FnGhost for F {}
#[doc(hidden)]
#[intrinsic("fn_ghost_wrapper")]
pub struct FnGhostWrapper<F>(pub F);
impl<F: Clone> Clone for FnGhostWrapper<F> {
#[ensures(F::clone.postcondition((&self.0,), result.0))]
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<F: Copy> Copy for FnGhostWrapper<F> {}
#[cfg(creusot)]
impl<I: core::marker::Tuple, F: FnOnce<I>> FnOnce<I> for FnGhostWrapper<F> {
type Output = F::Output;
#[trusted]
#[trusted(ghost)]
#[requires(self.precondition(args))]
#[ensures(self.postcondition_once(args, result))]
extern "rust-call" fn call_once(self, args: I) -> Self::Output {
self.0.call_once(args)
}
}
#[cfg(creusot)]
impl<I: core::marker::Tuple, F: FnMut<I>> FnMut<I> for FnGhostWrapper<F> {
#[trusted]
#[trusted(ghost)]
#[requires((*self).precondition(args))]
#[ensures((*self).postcondition_mut(args, ^self, result))]
extern "rust-call" fn call_mut(&mut self, args: I) -> Self::Output {
self.0.call_mut(args)
}
}
#[cfg(creusot)]
impl<I: core::marker::Tuple, F: Fn<I>> Fn<I> for FnGhostWrapper<F> {
#[trusted]
#[trusted(ghost)]
#[requires((*self).precondition(args))]
#[ensures((*self).postcondition(args, result))]
extern "rust-call" fn call(&self, args: I) -> Self::Output {
self.0.call(args)
}
}
impl<F> FnGhostWrapper<F> {
#[doc(hidden)]
#[check(ghost)]
#[ensures(result.0 == f)]
pub fn __new(f: F) -> Self {
Self(f)
}
}
#[cfg(creusot)]
impl<F> private::_Sealed for FnGhostWrapper<F> {}
#[cfg(creusot)]
impl<F> FnGhost for FnGhostWrapper<F> {}