@@ -1798,7 +1798,10 @@ impl<T> NonNull<[T]> {
1798
1798
#[ unstable( feature = "slice_ptr_get" , issue = "74265" ) ]
1799
1799
#[ rustc_const_unstable( feature = "const_index" , issue = "143775" ) ]
1800
1800
#[ inline]
1801
- #[ requires( ub_checks:: can_dereference( self . as_ptr( ) ) ) ] // Ensure self can be dereferenced
1801
+ // TODO: const_trait parsing weirdly interacts with attaching contracts, see
1802
+ // https://github.com/model-checking/verify-rust-std/issues/465,
1803
+ // https://github.com/model-checking/kani/issues/4303
1804
+ // #[requires(ub_checks::can_dereference(self.as_ptr()))] // Ensure self can be dereferenced
1802
1805
pub const unsafe fn get_unchecked_mut < I > ( self , index : I ) -> NonNull < I :: Output >
1803
1806
where
1804
1807
I : [ const ] SliceIndex < [ T ] > ,
@@ -2294,24 +2297,27 @@ mod verify {
2294
2297
}
2295
2298
}
2296
2299
2297
- #[ kani:: proof_for_contract( NonNull :: get_unchecked_mut) ]
2298
- pub fn non_null_check_get_unchecked_mut ( ) {
2299
- const ARR_SIZE : usize = 100000 ;
2300
- let mut arr: [ i32 ; ARR_SIZE ] = kani:: any ( ) ;
2301
- let raw_ptr = arr. as_mut_ptr ( ) ;
2302
- let ptr = NonNull :: slice_from_raw_parts ( NonNull :: new ( raw_ptr) . unwrap ( ) , ARR_SIZE ) ;
2303
- let lower = kani:: any_where ( |x| * x < ARR_SIZE ) ;
2304
- let upper = kani:: any_where ( |x| * x < ARR_SIZE && * x >= lower) ;
2305
- unsafe {
2306
- // NOTE: The `index` parameter cannot be used in the function contracts without being moved.
2307
- // Since the `SliceIndex` trait does not guarantee that `index` implements `Clone` or `Copy`,
2308
- // it cannot be reused after being consumed in the precondition. To comply with Rust's ownership
2309
- // rules and ensure `index` is only used once, the in-bounds check is moved to the proof harness
2310
- // as a workaround.
2311
- kani:: assume ( ptr. as_ref ( ) . get ( lower..upper) . is_some ( ) ) ;
2312
- let _ = ptr. get_unchecked_mut ( lower..upper) ;
2313
- }
2314
- }
2300
+ // TODO: const_trait parsing weirdly interacts with attaching contracts, see
2301
+ // https://github.com/model-checking/verify-rust-std/issues/465,
2302
+ // https://github.com/model-checking/kani/issues/4303
2303
+ // #[kani::proof_for_contract(NonNull::get_unchecked_mut)]
2304
+ // pub fn non_null_check_get_unchecked_mut() {
2305
+ // const ARR_SIZE: usize = 100000;
2306
+ // let mut arr: [i32; ARR_SIZE] = kani::any();
2307
+ // let raw_ptr = arr.as_mut_ptr();
2308
+ // let ptr = NonNull::slice_from_raw_parts(NonNull::new(raw_ptr).unwrap(), ARR_SIZE);
2309
+ // let lower = kani::any_where(|x| *x < ARR_SIZE);
2310
+ // let upper = kani::any_where(|x| *x < ARR_SIZE && *x >= lower);
2311
+ // unsafe {
2312
+ // // NOTE: The `index` parameter cannot be used in the function contracts without being moved.
2313
+ // // Since the `SliceIndex` trait does not guarantee that `index` implements `Clone` or `Copy`,
2314
+ // // it cannot be reused after being consumed in the precondition. To comply with Rust's ownership
2315
+ // // rules and ensure `index` is only used once, the in-bounds check is moved to the proof harness
2316
+ // // as a workaround.
2317
+ // kani::assume(ptr.as_ref().get(lower..upper).is_some());
2318
+ // let _ = ptr.get_unchecked_mut(lower..upper);
2319
+ // }
2320
+ // }
2315
2321
2316
2322
#[ kani:: proof_for_contract( NonNull :: replace) ]
2317
2323
pub fn non_null_check_replace ( ) {
0 commit comments