Skip to content

Commit eea35b0

Browse files
committed
Refactors contracts to be tool agnostic
1 parent 338c659 commit eea35b0

File tree

4 files changed

+107
-19
lines changed

4 files changed

+107
-19
lines changed

library/Cargo.lock

+88
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

library/core/src/ptr/const_ptr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,12 @@ impl<T: ?Sized> *const T {
482482
// overflow and that both pointers `self` and the result are in the same
483483
// allocation
484484
((self.addr() as isize).checked_add(count).is_some() &&
485-
kani::mem::same_allocation(self, self.wrapping_byte_offset(count)))
485+
core::ub_checks::same_allocation(self, self.wrapping_byte_offset(count)))
486486
)]
487487
#[ensures(|&result|
488488
// The resulting pointer should either be unchanged or still point to the same allocation
489489
(self.addr() == result.addr()) ||
490-
(kani::mem::same_allocation(self, result))
490+
(core::ub_checks::same_allocation(self, result))
491491
)]
492492
pub const unsafe fn byte_offset(self, count: isize) -> Self {
493493
// SAFETY: the caller must uphold the safety contract for `offset`.
@@ -1034,12 +1034,12 @@ impl<T: ?Sized> *const T {
10341034
// overflow and that both pointers `self` and the result are in the same
10351035
// allocation
10361036
((self.addr() as isize).checked_add(count as isize).is_some() &&
1037-
kani::mem::same_allocation(self, self.wrapping_byte_add(count)))
1037+
core::ub_checks::same_allocation(self, self.wrapping_byte_add(count)))
10381038
)]
10391039
#[ensures(|&result|
10401040
// The resulting pointer should either be unchanged or still point to the same allocation
10411041
(self.addr() == result.addr()) ||
1042-
(kani::mem::same_allocation(self, result))
1042+
(core::ub_checks::same_allocation(self, result))
10431043
)]
10441044
pub const unsafe fn byte_add(self, count: usize) -> Self {
10451045
// SAFETY: the caller must uphold the safety contract for `add`.
@@ -1178,12 +1178,12 @@ impl<T: ?Sized> *const T {
11781178
// cause overflow and that both pointers `self` and the result are in the
11791179
// same allocation
11801180
((self.addr() as isize).checked_sub(count as isize).is_some() &&
1181-
kani::mem::same_allocation(self, self.wrapping_byte_sub(count)))
1181+
core::ub_checks::same_allocation(self, self.wrapping_byte_sub(count)))
11821182
)]
11831183
#[ensures(|&result|
11841184
// The resulting pointer should either be unchanged or still point to the same allocation
11851185
(self.addr() == result.addr()) ||
1186-
(kani::mem::same_allocation(self, result))
1186+
(core::ub_checks::same_allocation(self, result))
11871187
)]
11881188
pub const unsafe fn byte_sub(self, count: usize) -> Self {
11891189
// SAFETY: the caller must uphold the safety contract for `sub`.

library/core/src/ptr/mut_ptr.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -477,17 +477,17 @@ impl<T: ?Sized> *mut T {
477477
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
478478
#[requires(
479479
// If count is zero, any pointer is valid including null pointer.
480-
(count == 0) ||
480+
(count == 0) ||
481481
// Else if count is not zero, then ensure that subtracting `count` doesn't
482482
// cause overflow and that both pointers `self` and the result are in the
483483
// same allocation
484-
((self.addr() as isize).checked_add(count).is_some() &&
485-
kani::mem::same_allocation(self, self.wrapping_byte_offset(count)))
484+
((self.addr() as isize).checked_add(count).is_some() &&
485+
core::ub_checks::same_allocation(self, self.wrapping_byte_offset(count)))
486486
)]
487487
#[ensures(|&result|
488488
// The resulting pointer should either be unchanged or still point to the same allocation
489489
(self.addr() == result.addr()) ||
490-
(kani::mem::same_allocation(self, result))
490+
(core::ub_checks::same_allocation(self, result))
491491
)]
492492
pub const unsafe fn byte_offset(self, count: isize) -> Self {
493493
// SAFETY: the caller must uphold the safety contract for `offset`.
@@ -1102,17 +1102,17 @@ impl<T: ?Sized> *mut T {
11021102
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
11031103
#[requires(
11041104
// If count is zero, any pointer is valid including null pointer.
1105-
(count == 0) ||
1105+
(count == 0) ||
11061106
// Else if count is not zero, then ensure that subtracting `count` doesn't
11071107
// cause overflow and that both pointers `self` and the result are in the
11081108
// same allocation
1109-
((self.addr() as isize).checked_add(count as isize).is_some() &&
1110-
kani::mem::same_allocation(self, self.wrapping_byte_add(count)))
1109+
((self.addr() as isize).checked_add(count as isize).is_some() &&
1110+
core::ub_checks::same_allocation(self, self.wrapping_byte_add(count)))
11111111
)]
11121112
#[ensures(|&result|
11131113
// The resulting pointer should either be unchanged or still point to the same allocation
11141114
(self.addr() == result.addr()) ||
1115-
(kani::mem::same_allocation(self, result))
1115+
(core::ub_checks::same_allocation(self, result))
11161116
)]
11171117
pub const unsafe fn byte_add(self, count: usize) -> Self {
11181118
// SAFETY: the caller must uphold the safety contract for `add`.
@@ -1248,17 +1248,17 @@ impl<T: ?Sized> *mut T {
12481248
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
12491249
#[requires(
12501250
// If count is zero, any pointer is valid including null pointer.
1251-
(count == 0) ||
1251+
(count == 0) ||
12521252
// Else if count is not zero, then ensure that subtracting `count` doesn't
12531253
// cause overflow and that both pointers `self` and the result are in the
12541254
// same allocation
1255-
((self.addr() as isize).checked_sub(count as isize).is_some() &&
1256-
kani::mem::same_allocation(self, self.wrapping_byte_sub(count)))
1255+
((self.addr() as isize).checked_sub(count as isize).is_some() &&
1256+
core::ub_checks::same_allocation(self, self.wrapping_byte_sub(count)))
12571257
)]
12581258
#[ensures(|&result|
12591259
// The resulting pointer should either be unchanged or still point to the same allocation
12601260
(self.addr() == result.addr()) ||
1261-
(kani::mem::same_allocation(self, result))
1261+
(core::ub_checks::same_allocation(self, result))
12621262
)]
12631263
pub const unsafe fn byte_sub(self, count: usize) -> Self {
12641264
// SAFETY: the caller must uphold the safety contract for `sub`.

0 commit comments

Comments
 (0)