File tree 5 files changed +66
-1
lines changed
tests/ui/derive-arbitrary
5 files changed +66
-1
lines changed Original file line number Diff line number Diff line change 3
3
4
4
//! This module introduces the Arbitrary trait as well as implementation for primitive types and
5
5
//! other std containers.
6
- use std:: num:: * ;
6
+ use std:: {
7
+ marker:: { PhantomData , PhantomPinned } ,
8
+ num:: * ,
9
+ } ;
7
10
8
11
/// This trait should be used to generate symbolic variables that represent any valid value of
9
12
/// its type.
@@ -120,3 +123,15 @@ where
120
123
if bool:: any ( ) { Ok ( T :: any ( ) ) } else { Err ( E :: any ( ) ) }
121
124
}
122
125
}
126
+
127
+ impl < T : ?Sized > Arbitrary for std:: marker:: PhantomData < T > {
128
+ fn any ( ) -> Self {
129
+ PhantomData
130
+ }
131
+ }
132
+
133
+ impl Arbitrary for std:: marker:: PhantomPinned {
134
+ fn any ( ) -> Self {
135
+ PhantomPinned
136
+ }
137
+ }
Original file line number Diff line number Diff line change
1
+ VERIFICATION:- SUCCESSFUL
Original file line number Diff line number Diff line change
1
+ // Copyright Kani Contributors
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ //! Check that Kani can automatically derive `Arbitrary` on a struct that has
5
+ //! `std::marker::PhantomData`
6
+
7
+ #[ derive( kani:: Arbitrary ) ]
8
+ struct Foo < T > {
9
+ x : i32 ,
10
+ _f : std:: marker:: PhantomData < T > ,
11
+ }
12
+
13
+ impl < T > Foo < T > {
14
+ fn new ( v : i32 ) -> Self {
15
+ Self { x : v, _f : std:: marker:: PhantomData }
16
+ }
17
+ }
18
+
19
+ #[ kani:: proof]
20
+ fn main ( ) {
21
+ let x = kani:: any ( ) ;
22
+ let f: Foo < u16 > = Foo :: new ( x) ;
23
+ assert_eq ! ( f. x, x) ;
24
+ }
Original file line number Diff line number Diff line change
1
+ VERIFICATION:- SUCCESSFUL
Original file line number Diff line number Diff line change
1
+ // Copyright Kani Contributors
2
+ // SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ //! Check that Kani can automatically derive `Arbitrary` on a struct that has
5
+ //! `std::marker::PhantomPinned`
6
+
7
+ #[ derive( kani:: Arbitrary ) ]
8
+ struct Foo {
9
+ x : i32 ,
10
+ _f : std:: marker:: PhantomPinned ,
11
+ }
12
+
13
+ impl Foo {
14
+ fn new ( v : i32 ) -> Self {
15
+ Self { x : v, _f : std:: marker:: PhantomPinned }
16
+ }
17
+ }
18
+
19
+ #[ kani:: proof]
20
+ fn check_arbitrary_phantom_pinned ( ) {
21
+ let x = kani:: any ( ) ;
22
+ let f: Foo = Foo :: new ( x) ;
23
+ assert_eq ! ( f. x, x) ;
24
+ }
You can’t perform that action at this time.
0 commit comments