@@ -320,25 +320,31 @@ impl<T: ?Sized> *const T {
320
320
/// * Both pointers must be *derived from* a pointer to the same object.
321
321
/// (See below for an example.)
322
322
///
323
- /// * The distance between the pointers, **in bytes**, cannot overflow an `isize`.
324
- ///
325
323
/// * The distance between the pointers, in bytes, must be an exact multiple
326
324
/// of the size of `T`.
327
325
///
326
+ /// * The distance between the pointers, **in bytes**, cannot overflow an `isize`.
327
+ ///
328
328
/// * The distance being in bounds cannot rely on "wrapping around" the address space.
329
329
///
330
- /// The compiler and standard library generally try to ensure allocations
331
- /// never reach a size where an offset is a concern. For instance, `Vec`
332
- /// and `Box` ensure they never allocate more than `isize::MAX` bytes, so
333
- /// `ptr_into_vec.offset_from(vec.as_ptr())` is always safe.
330
+ /// Rust types are never larger than `isize::MAX` and Rust allocations never wrap around the
331
+ /// address space, so two pointers within some value of any Rust type `T` will always satisfy
332
+ /// the last two conditions. The standard library also generally ensures that allocations
333
+ /// never reach a size where an offset is a concern. For instance, `Vec` and `Box` ensure they
334
+ /// never allocate more than `isize::MAX` bytes, so `ptr_into_vec.offset_from(vec.as_ptr())`
335
+ /// always satisfies the last two conditions.
334
336
///
335
- /// Most platforms fundamentally can't even construct such an allocation.
337
+ /// Most platforms fundamentally can't even construct such a large allocation.
336
338
/// For instance, no known 64-bit platform can ever serve a request
337
339
/// for 2<sup>63</sup> bytes due to page-table limitations or splitting the address space.
338
340
/// However, some 32-bit and 16-bit platforms may successfully serve a request for
339
341
/// more than `isize::MAX` bytes with things like Physical Address
340
342
/// Extension. As such, memory acquired directly from allocators or memory
341
343
/// mapped files *may* be too large to handle with this function.
344
+ /// (Note that [`offset`] and [`add`] also have a similar limitation and hence cannot be used on
345
+ /// such large allocations either.)
346
+ ///
347
+ /// [`add`]: #method.add
342
348
///
343
349
/// # Panics
344
350
///
0 commit comments