From 05a2bf7f34485462384ccbff616948d925e4fe4c Mon Sep 17 00:00:00 2001 From: Xuyang Zhang Date: Sat, 11 Jul 2026 13:51:06 +0800 Subject: [PATCH] doc: use ptr::addr in offset_from docs --- library/core/src/ptr/const_ptr.rs | 5 ++--- library/core/src/ptr/mut_ptr.rs | 5 ++--- library/core/src/ptr/non_null.rs | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 56f6a561f4bb9..1dc6a9f9f105e 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -567,9 +567,8 @@ impl *const T { /// needed for `const`-compatibility: the distance between pointers into *different* allocated /// objects is not known at compile-time. 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 isize - - /// origin as isize) / size_of::()`. - // FIXME: recommend `addr()` instead of `as usize` once that is stable. + /// pointers that are not guaranteed to be from the same allocation, use + /// `(self.addr() as isize - origin.addr() as isize) / size_of::()`. /// /// [`add`]: #method.add /// [allocation]: crate::ptr#allocation diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index b333f8217b2c0..c7585fde42180 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -748,9 +748,8 @@ impl *mut T { /// needed for `const`-compatibility: the distance between pointers into *different* allocated /// objects is not known at compile-time. 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 isize - - /// origin as isize) / size_of::()`. - // FIXME: recommend `addr()` instead of `as usize` once that is stable. + /// pointers that are not guaranteed to be from the same allocation, use + /// `(self.addr() as isize - origin.addr() as isize) / size_of::()`. /// /// [`add`]: #method.add /// [allocation]: crate::ptr#allocation diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index 6ec34206a4248..d2c2a88bbd08b 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -736,9 +736,8 @@ impl NonNull { /// needed for `const`-compatibility: the distance between pointers into *different* allocated /// objects is not known at compile-time. 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 isize - - /// origin as isize) / size_of::()`. - // FIXME: recommend `addr()` instead of `as usize` once that is stable. + /// pointers that are not guaranteed to be from the same allocation, use + /// `(self.addr() as isize - origin.addr() as isize) / size_of::()`. /// /// [`add`]: #method.add /// [allocation]: crate::ptr#allocation