Skip to content

Commit 69d7751

Browse files
update contracts
1 parent 505f90b commit 69d7751

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

library/core/src/ptr/non_null.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,10 @@ impl<T: ?Sized> NonNull<T> {
502502
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
503503
#[stable(feature = "non_null_convenience", since = "1.80.0")]
504504
#[rustc_const_stable(feature = "non_null_convenience", since = "1.80.0")]
505-
#[kani::requires(kani::mem::same_allocation(self.as_ptr() as *const(), self.as_ptr().byte_offset(count) as *const()))]
505+
#[kani::requires(
506+
count <= isize::MAX &&
507+
kani::mem::same_allocation(self.as_ptr() as *const(), self.as_ptr().byte_offset(count) as *const())
508+
)]
506509
#[kani::ensures(|result: &Self| result.as_ptr() == self.as_ptr().byte_offset(count))]
507510
pub const unsafe fn byte_offset(self, count: isize) -> Self {
508511
// SAFETY: the caller must uphold the safety contract for `offset` and `byte_offset` has
@@ -581,10 +584,10 @@ impl<T: ?Sized> NonNull<T> {
581584
#[rustc_allow_const_fn_unstable(set_ptr_value)]
582585
#[stable(feature = "non_null_convenience", since = "1.80.0")]
583586
#[rustc_const_stable(feature = "non_null_convenience", since = "1.80.0")]
584-
#[kani::requires(kani::mem::same_allocation(
585-
self.as_ptr() as *const(),
586-
((self.as_ptr() as *const () as usize) + count) as *const()
587-
))]
587+
#[kani::requires(
588+
count <= usize::MAX &&
589+
kani::mem::same_allocation(self.as_ptr() as *const(), (self.as_ptr().byte_add(count)) as *const())
590+
)]
588591
#[kani::ensures(
589592
|result: &NonNull<T>|
590593
(result.as_ptr() as *const () as usize) == ((self.as_ptr() as *const () as usize) + count)
@@ -1829,9 +1832,6 @@ mod verify {
18291832
let ptr = unsafe { NonNull::new(raw_ptr.add(offset)).unwrap() };
18301833
let count: usize = kani::any();
18311834

1832-
kani::assume(count.checked_mul(mem::size_of::<i32>()).is_some());
1833-
kani::assume(count * mem::size_of::<i32>() <= (isize::MAX as usize));
1834-
18351835
unsafe {
18361836
let result = ptr.byte_add(count);
18371837
}
@@ -1846,8 +1846,6 @@ mod verify {
18461846
let ptr = unsafe { NonNull::new(raw_ptr.add(offset)).unwrap() };
18471847
let count: isize = kani::any();
18481848

1849-
kani::assume(count.checked_mul(mem::size_of::<i32>() as isize).is_some());
1850-
kani::assume(count * (mem::size_of::<i32>() as isize) <= (isize::MAX as isize));
18511849
unsafe {
18521850
let result = ptr.byte_offset(count);
18531851
}

0 commit comments

Comments
 (0)