Skip to main content

vstd/std_specs/
alloc.rs

1use super::super::prelude::*;
2use super::super::raw_ptr::MemContents;
3
4verus! {
5
6// this is a bit of a hack; verus treats Global specially already,
7// but putting this here helps Verus pick up all the trait impls for Global
8#[cfg(feature = "alloc")]
9#[verifier::external_type_specification]
10#[verifier::external_body]
11pub struct ExGlobal(alloc::alloc::Global);
12
13// Rc/Arc's Clone impls are bounded by this std marker trait, so their
14// assume_specifications must name it.
15#[cfg(feature = "alloc")]
16#[verifier::external_trait_specification]
17pub unsafe trait ExAllocatorClone: core::alloc::Allocator + Clone {
18    type ExternalTraitSpecificationFor: core::alloc::AllocatorClone;
19}
20
21// Likewise for Rc/Arc's `From<Vec<T, A>>` impls.
22#[cfg(feature = "alloc")]
23#[verifier::external_trait_specification]
24pub trait ExAllocatorNightly: core::alloc::Allocator {
25    type ExternalTraitSpecificationFor: alloc::alloc::AllocatorNightly;
26}
27
28#[cfg(feature = "alloc")]
29#[feature(liballoc_internals)]
30pub assume_specification<T, const N: usize>[ alloc::boxed::box_assume_init_into_vec_unsafe ](
31    vals: alloc::boxed::Box<core::mem::MaybeUninit<[T; N]>>,
32) -> (result: alloc::vec::Vec<T>)
33    requires
34        vals.mem_contents() is Init,
35    ensures
36        vals.mem_contents() matches MemContents::Init(array) && result@ == array@,
37;
38
39#[cfg(feature = "alloc")]
40#[feature(liballoc_internals)]
41pub assume_specification<T>[ alloc::intrinsics::write_box_via_move ](
42    _0: alloc::boxed::Box<core::mem::MaybeUninit<T>>,
43    v: T,
44) -> (result: alloc::boxed::Box<core::mem::MaybeUninit<T>>)
45    ensures
46        result.mem_contents() == MemContents::Init(v),
47;
48
49#[cfg(feature = "alloc")]
50#[feature(liballoc_internals)]
51pub assume_specification<T>[ alloc::boxed::Box::<T>::new_uninit ]() -> alloc::boxed::Box<
52    core::mem::MaybeUninit<T>,
53>
54;
55
56} // verus!