From 39b53dc204e944e37fef621d4799a561f423cfd3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 31 Jul 2023 14:24:11 +0200 Subject: [PATCH] documentation tweaks --- library/core/src/ptr/const_ptr.rs | 12 ++++++------ library/core/src/ptr/mut_ptr.rs | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index b89e9e260e7..97aa3015bf1 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -607,9 +607,8 @@ impl *const T { /// Calculates the distance between two pointers. The returned value is in /// units of T: the distance in bytes divided by `mem::size_of::()`. /// - /// This function is the inverse of [`offset`]: it is valid to call if and only if - /// `self` could have been computed as `origin.offset(n)` for some `n`, and it will - /// then return that `n`. + /// This function is the inverse of [`offset`]: it is valid to call and will return + /// `n` if and only if `origin.offset(n)` is valid to call and will return `self`. /// /// [`offset`]: #method.offset /// @@ -650,9 +649,10 @@ impl *const T { /// /// The requirement for pointers to be derived from the same allocated object is primarily /// needed for `const`-compatibility: at compile-time, pointers into *different* allocated - /// object do not have a known distance to each other. However, the requirement also exists at - /// runtime, and may be exploited by optimizations. You can use `(self as usize).sub(origin as - /// usize) / mem::size_of::()` to avoid this requirement. + /// objects do not have a known distance to each other. However, the requirement also exists at + /// runtime and may be exploited by optimizations. If you wish to compute the difference between + /// pointers that are not guaranteed to be from the same allocation, use `(self as + /// usize).sub(origin as usize) / mem::size_of::()`. /// /// [`add`]: #method.add /// [allocated object]: crate::ptr#allocated-object diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index e7611c90344..2f21319d559 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -781,9 +781,8 @@ impl *mut T { /// Calculates the distance between two pointers. The returned value is in /// units of T: the distance in bytes divided by `mem::size_of::()`. /// - /// This function is the inverse of [`offset`]: it is valid to call if and only if - /// `self` could have been computed as `origin.offset(n)` for some `n`, and it will - /// then return that `n`. + /// This function is the inverse of [`offset`]: it is valid to call and will return + /// `n` if and only if `origin.offset(n)` is valid to call and will return `self`. /// /// [`offset`]: pointer#method.offset-1 /// @@ -824,9 +823,10 @@ impl *mut T { /// /// The requirement for pointers to be derived from the same allocated object is primarily /// needed for `const`-compatibility: at compile-time, pointers into *different* allocated - /// object do not have a known distance to each other. However, the requirement also exists at - /// runtime, and may be exploited by optimizations. You can use `(self as usize).sub(origin as - /// usize) / mem::size_of::()` to avoid this requirement. + /// objects do not have a known distance to each other. However, the requirement also exists at + /// runtime and may be exploited by optimizations. If you wish to compute the difference between + /// pointers that are not guaranteed to be from the same allocation, use `(self as + /// usize).sub(origin as usize) / mem::size_of::()`. /// /// [`add`]: #method.add /// [allocated object]: crate::ptr#allocated-object