Skip to content

Commit 39b53dc

Browse files
committed
documentation tweaks
1 parent 62bdb1a commit 39b53dc

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

library/core/src/ptr/const_ptr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,8 @@ impl<T: ?Sized> *const T {
607607
/// Calculates the distance between two pointers. The returned value is in
608608
/// units of T: the distance in bytes divided by `mem::size_of::<T>()`.
609609
///
610-
/// This function is the inverse of [`offset`]: it is valid to call if and only if
611-
/// `self` could have been computed as `origin.offset(n)` for some `n`, and it will
612-
/// then return that `n`.
610+
/// This function is the inverse of [`offset`]: it is valid to call and will return
611+
/// `n` if and only if `origin.offset(n)` is valid to call and will return `self`.
613612
///
614613
/// [`offset`]: #method.offset
615614
///
@@ -650,9 +649,10 @@ impl<T: ?Sized> *const T {
650649
///
651650
/// The requirement for pointers to be derived from the same allocated object is primarily
652651
/// needed for `const`-compatibility: at compile-time, pointers into *different* allocated
653-
/// object do not have a known distance to each other. However, the requirement also exists at
654-
/// runtime, and may be exploited by optimizations. You can use `(self as usize).sub(origin as
655-
/// usize) / mem::size_of::<T>()` to avoid this requirement.
652+
/// objects do not have a known distance to each other. However, the requirement also exists at
653+
/// runtime and may be exploited by optimizations. If you wish to compute the difference between
654+
/// pointers that are not guaranteed to be from the same allocation, use `(self as
655+
/// usize).sub(origin as usize) / mem::size_of::<T>()`.
656656
///
657657
/// [`add`]: #method.add
658658
/// [allocated object]: crate::ptr#allocated-object

library/core/src/ptr/mut_ptr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,8 @@ impl<T: ?Sized> *mut T {
781781
/// Calculates the distance between two pointers. The returned value is in
782782
/// units of T: the distance in bytes divided by `mem::size_of::<T>()`.
783783
///
784-
/// This function is the inverse of [`offset`]: it is valid to call if and only if
785-
/// `self` could have been computed as `origin.offset(n)` for some `n`, and it will
786-
/// then return that `n`.
784+
/// This function is the inverse of [`offset`]: it is valid to call and will return
785+
/// `n` if and only if `origin.offset(n)` is valid to call and will return `self`.
787786
///
788787
/// [`offset`]: pointer#method.offset-1
789788
///
@@ -824,9 +823,10 @@ impl<T: ?Sized> *mut T {
824823
///
825824
/// The requirement for pointers to be derived from the same allocated object is primarily
826825
/// needed for `const`-compatibility: at compile-time, pointers into *different* allocated
827-
/// object do not have a known distance to each other. However, the requirement also exists at
828-
/// runtime, and may be exploited by optimizations. You can use `(self as usize).sub(origin as
829-
/// usize) / mem::size_of::<T>()` to avoid this requirement.
826+
/// objects do not have a known distance to each other. However, the requirement also exists at
827+
/// runtime and may be exploited by optimizations. If you wish to compute the difference between
828+
/// pointers that are not guaranteed to be from the same allocation, use `(self as
829+
/// usize).sub(origin as usize) / mem::size_of::<T>()`.
830830
///
831831
/// [`add`]: #method.add
832832
/// [allocated object]: crate::ptr#allocated-object

0 commit comments

Comments
 (0)