Skip to content

Commit 7ce2d89

Browse files
simplify contract for byte_offset
1 parent fff0e6a commit 7ce2d89

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

library/core/src/ptr/non_null.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -502,22 +502,8 @@ 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(
506-
if (count >= 0) {
507-
kani::mem::same_allocation(self.as_ptr() as *const(), self.as_ptr().byte_add(count as usize) as *const())
508-
} else {
509-
kani::mem::same_allocation(self.as_ptr() as *const(), self.as_ptr().byte_sub(-count as usize) as *const())
510-
}
511-
)]
512-
#[kani::ensures(|result: &Self| {
513-
if (count >= 0) {
514-
let offset_ptr = self.as_ptr().byte_add(count as usize) as *mut T;
515-
result.as_ptr() == offset_ptr
516-
} else {
517-
let offset_ptr = self.as_ptr().byte_sub(-count as usize) as *mut T;
518-
result.as_ptr() == offset_ptr
519-
}
520-
})]
505+
#[kani::requires(kani::mem::same_allocation(self.as_ptr() as *const(), self.as_ptr().byte_offset(count) as *const()))]
506+
#[kani::ensures(|result: &Self| result.as_ptr() == self.as_ptr().byte_offset(count))]
521507
pub const unsafe fn byte_offset(self, count: isize) -> Self {
522508
// SAFETY: the caller must uphold the safety contract for `offset` and `byte_offset` has
523509
// the same safety contract.

0 commit comments

Comments
 (0)