Skip to content

Commit 6c27373

Browse files
committed
clarify is_inbounds docs
1 parent 71b0e86 commit 6c27373

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

library/kani_core/src/mem.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,14 @@ macro_rules! kani_mem {
168168

169169
/// Checks that `ptr` points to an allocation that can hold data of size calculated from `T`.
170170
///
171-
/// This will panic if `ptr` points to an invalid `non_null`
172-
/// Returns `false` if:
173-
/// - The computed size overflows.
174-
/// - The computed size exceeds `isize::MAX`.
175-
/// - The pointer is null (except for zero-sized types).
176-
/// - The pointer references unallocated memory.
177-
///
178-
/// This function aligns with Rust's memory safety requirements, which restrict valid allocations
179-
/// to sizes no larger than `isize::MAX`.
171+
/// This function always returns `true` for ZSTs, since every pointer to a ZST is valid.
172+
/// For non-ZSTs, this function will:
173+
/// - Panic if `ptr` does not point to allocated memory,
174+
/// - Return `false` if the size of the val pointed to exceeds `isize::MAX`,
175+
/// - Return `false` if the pointer is null.
176+
///
177+
/// If none of the above conditions hold, it will return `true` if and only if
178+
/// `ptr` points to allocated memory that can hold data of size calculated from `T`.
180179
#[crate::kani::unstable_feature(
181180
feature = "mem-predicates",
182181
issue = 3946,
@@ -192,7 +191,7 @@ macro_rules! kani_mem {
192191
} else {
193192
// Note that this branch can't be tested in concrete execution as `is_read_ok` needs to be
194193
// stubbed.
195-
// We first assert that the data_ptr
194+
// We first assert that the data_ptr points to a valid allocation.
196195
let data_ptr = ptr as *const ();
197196
if !unsafe { is_allocated(data_ptr, 0) } {
198197
crate::kani::unsupported(

0 commit comments

Comments
 (0)