12
12
macro_rules! kani_mem {
13
13
( $core: tt) => {
14
14
use super :: kani_intrinsic;
15
+ use $core:: marker:: MetaSized ;
15
16
use $core:: ptr:: { DynMetadata , NonNull , Pointee } ;
16
17
17
18
/// Check if the pointer is valid for write access according to [crate::mem] conditions 1, 2
@@ -31,7 +32,7 @@ macro_rules! kani_mem {
31
32
issue = 2690 ,
32
33
reason = "experimental memory predicate API"
33
34
) ]
34
- pub fn can_write<T : ? Sized >( ptr: * mut T ) -> bool {
35
+ pub fn can_write<T : MetaSized >( ptr: * mut T ) -> bool {
35
36
is_ptr_aligned( ptr) && is_inbounds( ptr)
36
37
}
37
38
@@ -49,7 +50,7 @@ macro_rules! kani_mem {
49
50
issue = 2690 ,
50
51
reason = "experimental memory predicate API"
51
52
) ]
52
- pub fn can_write_unaligned<T : ? Sized >( ptr: * const T ) -> bool {
53
+ pub fn can_write_unaligned<T : MetaSized >( ptr: * const T ) -> bool {
53
54
let ( thin_ptr, metadata) = ptr. to_raw_parts( ) ;
54
55
is_inbounds( ptr)
55
56
}
@@ -72,7 +73,7 @@ macro_rules! kani_mem {
72
73
reason = "experimental memory predicate API"
73
74
) ]
74
75
#[ allow( clippy:: not_unsafe_ptr_arg_deref) ]
75
- pub fn can_dereference<T : ? Sized >( ptr: * const T ) -> bool {
76
+ pub fn can_dereference<T : MetaSized >( ptr: * const T ) -> bool {
76
77
// Need to assert `is_initialized` because non-determinism is used under the hood, so it
77
78
// does not make sense to use it inside assumption context.
78
79
is_ptr_aligned( ptr)
@@ -99,7 +100,7 @@ macro_rules! kani_mem {
99
100
reason = "experimental memory predicate API"
100
101
) ]
101
102
#[ allow( clippy:: not_unsafe_ptr_arg_deref) ]
102
- pub fn can_read_unaligned<T : ? Sized >( ptr: * const T ) -> bool {
103
+ pub fn can_read_unaligned<T : MetaSized >( ptr: * const T ) -> bool {
103
104
let ( thin_ptr, metadata) = ptr. to_raw_parts( ) ;
104
105
// Need to assert `is_initialized` because non-determinism is used under the hood, so it
105
106
// does not make sense to use it inside assumption context.
@@ -116,12 +117,15 @@ macro_rules! kani_mem {
116
117
reason = "experimental memory predicate API"
117
118
) ]
118
119
#[ allow( clippy:: not_unsafe_ptr_arg_deref) ]
119
- pub fn same_allocation<T : ? Sized >( ptr1: * const T , ptr2: * const T ) -> bool {
120
+ pub fn same_allocation<T : MetaSized >( ptr1: * const T , ptr2: * const T ) -> bool {
120
121
same_allocation_internal( ptr1, ptr2)
121
122
}
122
123
123
124
#[ allow( clippy:: not_unsafe_ptr_arg_deref) ]
124
- pub ( super ) fn same_allocation_internal<T : ?Sized >( ptr1: * const T , ptr2: * const T ) -> bool {
125
+ pub ( super ) fn same_allocation_internal<T : MetaSized >(
126
+ ptr1: * const T ,
127
+ ptr2: * const T ,
128
+ ) -> bool {
125
129
let addr1 = ptr1 as * const ( ) ;
126
130
let addr2 = ptr2 as * const ( ) ;
127
131
cbmc:: same_allocation( addr1, addr2)
@@ -135,7 +139,7 @@ macro_rules! kani_mem {
135
139
/// - The computed size exceeds `isize::MAX` (the maximum safe Rust allocation size).
136
140
/// TODO: Optimize this if T is sized.
137
141
#[ kanitool:: fn_marker = "CheckedSizeOfIntrinsic" ]
138
- pub fn checked_size_of_raw<T : ? Sized >( ptr: * const T ) -> Option <usize > {
142
+ pub fn checked_size_of_raw<T : MetaSized >( ptr: * const T ) -> Option <usize > {
139
143
#[ cfg( not( feature = "concrete_playback" ) ) ]
140
144
return kani_intrinsic( ) ;
141
145
@@ -153,7 +157,7 @@ macro_rules! kani_mem {
153
157
/// Return `None` if alignment information cannot be retrieved (foreign types), or if value
154
158
/// is not power-of-two.
155
159
#[ kanitool:: fn_marker = "CheckedAlignOfIntrinsic" ]
156
- pub fn checked_align_of_raw<T : ? Sized >( ptr: * const T ) -> Option <usize > {
160
+ pub fn checked_align_of_raw<T : MetaSized >( ptr: * const T ) -> Option <usize > {
157
161
#[ cfg( not( feature = "concrete_playback" ) ) ]
158
162
return kani_intrinsic( ) ;
159
163
@@ -180,7 +184,7 @@ macro_rules! kani_mem {
180
184
issue = 3946 ,
181
185
reason = "experimental memory predicate API"
182
186
) ]
183
- pub fn is_inbounds<T : ? Sized >( ptr: * const T ) -> bool {
187
+ pub fn is_inbounds<T : MetaSized >( ptr: * const T ) -> bool {
184
188
// If size overflows, then pointer cannot be inbounds.
185
189
let Some ( sz) = checked_size_of_raw( ptr) else { return false } ;
186
190
if sz == 0 {
@@ -203,7 +207,7 @@ macro_rules! kani_mem {
203
207
204
208
// Return whether the pointer is aligned
205
209
#[ allow( clippy:: manual_is_power_of_two) ]
206
- fn is_ptr_aligned<T : ? Sized >( ptr: * const T ) -> bool {
210
+ fn is_ptr_aligned<T : MetaSized >( ptr: * const T ) -> bool {
207
211
// Cannot be aligned if pointer alignment cannot be computed.
208
212
let Some ( align) = checked_align_of_raw( ptr) else { return false } ;
209
213
if align > 0 && ( align & ( align - 1 ) ) == 0 {
@@ -237,19 +241,19 @@ macro_rules! kani_mem {
237
241
/// - Users have to ensure that the pointed to memory is allocated.
238
242
#[ kanitool:: fn_marker = "ValidValueIntrinsic" ]
239
243
#[ inline( never) ]
240
- unsafe fn has_valid_value<T : ? Sized >( _ptr: * const T ) -> bool {
244
+ unsafe fn has_valid_value<T : MetaSized >( _ptr: * const T ) -> bool {
241
245
kani_intrinsic( )
242
246
}
243
247
244
248
/// Check whether `len * size_of::<T>()` bytes are initialized starting from `ptr`.
245
249
#[ kanitool:: fn_marker = "IsInitializedIntrinsic" ]
246
250
#[ inline( never) ]
247
- pub ( crate ) fn is_initialized<T : ? Sized >( _ptr: * const T ) -> bool {
251
+ pub ( crate ) fn is_initialized<T : MetaSized >( _ptr: * const T ) -> bool {
248
252
kani_intrinsic( )
249
253
}
250
254
251
255
/// A helper to assert `is_initialized` to use it as a part of other predicates.
252
- fn assert_is_initialized<T : ? Sized >( ptr: * const T ) -> bool {
256
+ fn assert_is_initialized<T : MetaSized >( ptr: * const T ) -> bool {
253
257
super :: internal:: check(
254
258
is_initialized( ptr) ,
255
259
"Undefined Behavior: Reading from an uninitialized pointer" ,
@@ -277,7 +281,7 @@ macro_rules! kani_mem {
277
281
#[ doc( hidden) ]
278
282
#[ kanitool:: fn_marker = "PointerObjectHook" ]
279
283
#[ inline( never) ]
280
- pub ( crate ) fn pointer_object<T : ? Sized >( _ptr: * const T ) -> usize {
284
+ pub ( crate ) fn pointer_object<T : MetaSized >( _ptr: * const T ) -> usize {
281
285
kani_intrinsic( )
282
286
}
283
287
@@ -290,7 +294,7 @@ macro_rules! kani_mem {
290
294
) ]
291
295
#[ kanitool:: fn_marker = "PointerOffsetHook" ]
292
296
#[ inline( never) ]
293
- pub fn pointer_offset<T : ? Sized >( _ptr: * const T ) -> usize {
297
+ pub fn pointer_offset<T : MetaSized >( _ptr: * const T ) -> usize {
294
298
kani_intrinsic( )
295
299
}
296
300
} ;
0 commit comments