File tree 2 files changed +9
-0
lines changed
2 files changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -388,6 +388,12 @@ impl<T: ?Sized> *const T {
388
388
/// bounds of that allocated object. In particular, this range must not "wrap around" the edge
389
389
/// of the address space.
390
390
///
391
+ /// * Note that the special case of "one-past-the-end" pointers is explicitly allowed: a pointer
392
+ /// exactly one byte past the end of an allocated object (at address `base + size`, using the
393
+ /// terminology from [allocated object]) is valid for offset calculations, though dereferencing
394
+ /// such a pointer remains invalid. This allows for efficiently calculating ranges and detecting
395
+ /// the end of iteration.
396
+ ///
391
397
/// Allocated objects can never be larger than `isize::MAX` bytes, so if the computed offset
392
398
/// stays in bounds of the allocated object, it is guaranteed to satisfy the first requirement.
393
399
/// This implies, for instance, that `vec.as_ptr().add(vec.len())` (for `vec: Vec<T>`) is always
Original file line number Diff line number Diff line change 116
116
//! `addresses`, the following are guaranteed:
117
117
//! - For all addresses `a` in `addresses`, `a` is in the range `base .. (base +
118
118
//! size)` (note that this requires `a < base + size`, not `a <= base + size`)
119
+ //! - However, for pointer offset calculations, a special "one-past-the-end" address
120
+ //! exactly at `base + size` is considered valid, though this address should not be
121
+ //! dereferenced. This exception is crucial for iteration and range calculations.
119
122
//! - `base` is not equal to [`null()`] (i.e., the address with the numerical
120
123
//! value 0)
121
124
//! - `base + size <= usize::MAX`
You can’t perform that action at this time.
0 commit comments