From 94b938210a508f197a08c626d14356eadf556080 Mon Sep 17 00:00:00 2001 From: asquared31415 <34665709+asquared31415@users.noreply.github.com> Date: Tue, 9 Jun 2026 20:29:43 +0000 Subject: [PATCH] clarify that pointers are not always compared by their addresses --- library/core/src/ptr/const_ptr.rs | 21 ++++++++++++++++++--- library/core/src/ptr/mut_ptr.rs | 21 ++++++++++++++++++--- library/core/src/ptr/non_null.rs | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index b7fcd6a5cd3de..56136609854f5 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1584,7 +1584,12 @@ impl *const [T; N] { } } -/// Pointer equality is by address, as produced by the [`<*const T>::addr`](pointer::addr) method. +/// Pointers to [`Sized`] types are compared by their addresses, as produced by the +/// [`<*const T>::addr`](pointer::addr) method. +/// Pointers to [dynamically sized types] additionally have their metadata compared. +/// See [`core::ptr::eq`] for more information about metadata comparisons. +/// +/// [dynamically sized types]: https://doc.rust-lang.org/reference/dynamically-sized-types.html #[stable(feature = "rust1", since = "1.0.0")] #[diagnostic::on_const( message = "pointers cannot be reliably compared during const eval", @@ -1606,7 +1611,12 @@ impl PartialEq for *const T { )] impl Eq for *const T {} -/// Pointer comparison is by address, as produced by the `[`<*const T>::addr`](pointer::addr)` method. +/// Pointers to [`Sized`] types are compared by their addresses, as produced by the +/// [`<*const T>::addr`](pointer::addr) method. +/// Pointers to [dynamically sized types] additionally have their metadata compared. +/// See [`core::ptr::eq`] for more information about metadata comparisons. +/// +/// [dynamically sized types]: https://doc.rust-lang.org/reference/dynamically-sized-types.html #[stable(feature = "rust1", since = "1.0.0")] #[diagnostic::on_const( message = "pointers cannot be reliably compared during const eval", @@ -1626,7 +1636,12 @@ impl Ord for *const T { } } -/// Pointer comparison is by address, as produced by the `[`<*const T>::addr`](pointer::addr)` method. +/// Pointers to [`Sized`] types are compared by their addresses, as produced by the +/// [`<*const T>::addr`](pointer::addr) method. +/// Pointers to [dynamically sized types] additionally have their metadata compared. +/// See [`core::ptr::eq`] for more information about metadata comparisons. +/// +/// [dynamically sized types]: https://doc.rust-lang.org/reference/dynamically-sized-types.html #[stable(feature = "rust1", since = "1.0.0")] #[diagnostic::on_const( message = "pointers cannot be reliably compared during const eval", diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index fd8dafa18f56b..15223de7bca69 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -2025,7 +2025,12 @@ impl *mut [T; N] { } } -/// Pointer equality is by address, as produced by the [`<*mut T>::addr`](pointer::addr) method. +/// Pointers to [`Sized`] types are compared by their addresses, as produced by the +/// [`<*mut T>::addr`](pointer::addr) method. +/// Pointers to [dynamically sized types] additionally have their metadata compared. +/// See [`core::ptr::eq`] for more information about metadata comparisons. +/// +/// [dynamically sized types]: https://doc.rust-lang.org/reference/dynamically-sized-types.html #[stable(feature = "rust1", since = "1.0.0")] #[diagnostic::on_const( message = "pointers cannot be reliably compared during const eval", @@ -2047,7 +2052,12 @@ impl PartialEq for *mut T { )] impl Eq for *mut T {} -/// Pointer comparison is by address, as produced by the [`<*mut T>::addr`](pointer::addr) method. +/// Pointers to [`Sized`] types are compared by their addresses, as produced by the +/// [`<*mut T>::addr`](pointer::addr) method. +/// Pointers to [dynamically sized types] additionally have their metadata compared. +/// See [`core::ptr::eq`] for more information about metadata comparisons. +/// +/// [dynamically sized types]: https://doc.rust-lang.org/reference/dynamically-sized-types.html #[stable(feature = "rust1", since = "1.0.0")] #[diagnostic::on_const( message = "pointers cannot be reliably compared during const eval", @@ -2067,7 +2077,12 @@ impl Ord for *mut T { } } -/// Pointer comparison is by address, as produced by the [`<*mut T>::addr`](pointer::addr) method. +/// Pointers to [`Sized`] types are compared by their addresses, as produced by the +/// [`<*mut T>::addr`](pointer::addr) method. +/// Pointers to [dynamically sized types] additionally have their metadata compared. +/// See [`core::ptr::eq`] for more information about metadata comparisons. +/// +/// [dynamically sized types]: https://doc.rust-lang.org/reference/dynamically-sized-types.html #[stable(feature = "rust1", since = "1.0.0")] #[diagnostic::on_const( message = "pointers cannot be reliably compared during const eval", diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index bafc37469b32f..09770f2343aeb 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1642,6 +1642,12 @@ impl fmt::Pointer for NonNull { #[stable(feature = "nonnull", since = "1.25.0")] impl Eq for NonNull {} +/// Pointers to [`Sized`] types are compared by their addresses, as produced by the +/// [`NonNull::addr`] method. +/// Pointers to [dynamically sized types] additionally have their metadata compared. +/// See [`core::ptr::eq`] for more information about metadata comparisons. +/// +/// [dynamically sized types]: https://doc.rust-lang.org/reference/dynamically-sized-types.html #[stable(feature = "nonnull", since = "1.25.0")] impl PartialEq for NonNull { #[inline] @@ -1651,6 +1657,12 @@ impl PartialEq for NonNull { } } +/// Pointers to [`Sized`] types are compared by their addresses, as produced by the +/// [`NonNull::addr`] method. +/// Pointers to [dynamically sized types] additionally have their metadata compared. +/// See [`core::ptr::eq`] for more information about metadata comparisons. +/// +/// [dynamically sized types]: https://doc.rust-lang.org/reference/dynamically-sized-types.html #[stable(feature = "nonnull", since = "1.25.0")] impl Ord for NonNull { #[inline] @@ -1660,6 +1672,12 @@ impl Ord for NonNull { } } +/// Pointers to [`Sized`] types are compared by their addresses, as produced by the +/// [`NonNull::addr`] method. +/// Pointers to [dynamically sized types] additionally have their metadata compared. +/// See [`core::ptr::eq`] for more information about metadata comparisons. +/// +/// [dynamically sized types]: https://doc.rust-lang.org/reference/dynamically-sized-types.html #[stable(feature = "nonnull", since = "1.25.0")] impl PartialOrd for NonNull { #[inline]