Skip to content

Commit 4d1388a

Browse files
committed
Disable get_unchecked_mut contract and harness
1 parent 0c849c7 commit 4d1388a

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

library/core/src/ptr/non_null.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,10 @@ impl<T> NonNull<[T]> {
17981798
#[unstable(feature = "slice_ptr_get", issue = "74265")]
17991799
#[rustc_const_unstable(feature = "const_index", issue = "143775")]
18001800
#[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
18021805
pub const unsafe fn get_unchecked_mut<I>(self, index: I) -> NonNull<I::Output>
18031806
where
18041807
I: [const] SliceIndex<[T]>,
@@ -2294,24 +2297,27 @@ mod verify {
22942297
}
22952298
}
22962299

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+
// }
23152321

23162322
#[kani::proof_for_contract(NonNull::replace)]
23172323
pub fn non_null_check_replace() {

0 commit comments

Comments
 (0)