Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions library/kani/src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,12 @@ impl Arbitrary for std::marker::PhantomPinned {
PhantomPinned
}
}

impl<T> Arbitrary for std::boxed::Box<T>
where
T: Arbitrary,
{
fn any() -> Self {
Box::new(T::any())
}
}
7 changes: 7 additions & 0 deletions tests/expected/derive-arbitrary/box/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Status: SATISFIED\
Description: "cover condition: *foo.boxed >= i32::MIN && *foo.boxed <= i32::MAX"
Status: UNSATISFIABLE\
Description: "cover condition: *foo.boxed < i32::MIN"
Status: UNSATISFIABLE\
Description: "cover condition: *foo.boxed > i32::MAX"
VERIFICATION:- SUCCESSFUL
18 changes: 18 additions & 0 deletions tests/expected/derive-arbitrary/box/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Check that Kani can automatically derive `Arbitrary` on a struct with a
//! member of type `Box<T>`
#[derive(kani::Arbitrary)]
struct Foo<T> {
boxed: Box<T>,
}

#[kani::proof]
fn main() {
let foo: Foo<i32> = kani::any();
kani::cover!(*foo.boxed >= i32::MIN && *foo.boxed <= i32::MAX);
kani::cover!(*foo.boxed < i32::MIN); // <-- this condition should be `UNSATISFIABLE`
kani::cover!(*foo.boxed > i32::MAX); // <-- this condition should be `UNSATISFIABLE`
}