#[cfg(creusot)]
use crate::std::ptr::PointerExt as _;
use crate::{logic::ops::DerefLogic, prelude::*};
#[cfg(feature = "nightly")]
use std::alloc::Allocator;
#[cfg(creusot)]
use std::ops::Deref;
use std::rc::Rc;
pub trait RcExt {
type Pointee: ?Sized;
#[logic]
fn as_ptr_logic(self) -> *const Self::Pointee;
}
#[cfg(feature = "nightly")]
impl<T: ?Sized, A: Allocator> RcExt for Rc<T, A> {
type Pointee = T;
#[logic(opaque)]
fn as_ptr_logic(self) -> *const T {
dead
}
}
#[cfg(feature = "nightly")]
impl<T: DeepModel + ?Sized, A: Allocator> DeepModel for Rc<T, A> {
type DeepModelTy = T::DeepModelTy;
#[logic(open, inline)]
fn deep_model(self) -> Self::DeepModelTy {
pearlite! { (*self).deep_model() }
}
}
#[cfg(feature = "nightly")]
impl<T: ?Sized, A: Allocator> DerefLogic for Rc<T, A> {
#[logic(opaque)]
fn deref_logic(&self) -> &T {
dead
}
}
extern_spec! {
#[trusted(positive(T))]
type Rc<T>;
impl<T> Rc<T> {
#[check(terminates)] #[ensures(*result == value)]
fn new(value: T) -> Self;
}
impl<T, A: Allocator> Rc<T, A> {
#[check(ghost)]
#[ensures(result == this.as_ptr_logic())]
#[ensures(!result.is_null_logic())]
fn as_ptr(this: &Rc<T, A>) -> *const T;
#[check(ghost)]
#[ensures(result == (this.as_ptr_logic().addr_logic() == other.as_ptr_logic().addr_logic()))]
#[ensures(result ==> this == other)]
fn ptr_eq(this: &Rc<T, A>, other: &Rc<T, A>) -> bool;
}
impl<T, A: Allocator> AsRef<T> for Rc<T, A> {
#[check(ghost)]
#[ensures(*result == **self)]
fn as_ref(&self) -> &T;
}
impl<T: ?Sized, A: Allocator + Clone> Clone for Rc<T, A> {
#[check(terminates)] #[ensures(result == *self)]
fn clone(&self) -> Rc<T, A>;
}
impl<T: ?Sized, A: Allocator> Deref for Rc<T, A> {
#[check(ghost)]
#[logic_alias(self.deref_logic())]
fn deref(&self) -> &T { self.as_ref() }
}
}
#[cfg(not(feature = "nightly"))]
impl<T: DeepModel + ?Sized> DeepModel for Rc<T> {
type DeepModelTy = T::DeepModelTy;
}
#[cfg(not(feature = "nightly"))]
impl<T: ?Sized> DerefLogic for Rc<T> {}