@@ -36,7 +36,10 @@ impl<T: ?Sized> *const T {
3636 pub const fn is_null ( self ) -> bool {
3737 // Compare via a cast to a thin pointer, so fat pointers are only
3838 // considering their "data" part for null-ness.
39- ( self as * const u8 ) . guaranteed_eq ( null ( ) )
39+ match ( self as * const u8 ) . guaranteed_eq ( null ( ) ) {
40+ None => false ,
41+ Some ( res) => res,
42+ }
4043 }
4144
4245 /// Casts to a pointer of another type.
@@ -770,20 +773,16 @@ impl<T: ?Sized> *const T {
770773
771774 /// Returns whether two pointers are guaranteed to be equal.
772775 ///
773- /// At runtime this function behaves like `self == other`.
776+ /// At runtime this function behaves like `Some( self == other) `.
774777 /// However, in some contexts (e.g., compile-time evaluation),
775778 /// it is not always possible to determine equality of two pointers, so this function may
776- /// spuriously return `false` for pointers that later actually turn out to be equal.
777- /// But when it returns `true`, the pointers are guaranteed to be equal.
778- ///
779- /// This function is the mirror of [`guaranteed_ne`], but not its inverse. There are pointer
780- /// comparisons for which both functions return `false`.
779+ /// spuriously return `None` for pointers that later actually turn out to have its equality known.
780+ /// But when it returns `Some`, the pointers' equality is guaranteed to be known.
781781 ///
782- /// [`guaranteed_ne`]: #method.guaranteed_ne
783- ///
784- /// The return value may change depending on the compiler version and unsafe code must not
782+ /// The return value may change from `Some` to `None` and vice versa depending on the compiler
783+ /// version and unsafe code must not
785784 /// rely on the result of this function for soundness. It is suggested to only use this function
786- /// for performance optimizations where spurious `false ` return values by this function do not
785+ /// for performance optimizations where spurious `None ` return values by this function do not
787786 /// affect the outcome, but just the performance.
788787 /// The consequences of using this method to make runtime and compile-time code behave
789788 /// differently have not been explored. This method should not be used to introduce such
@@ -792,29 +791,28 @@ impl<T: ?Sized> *const T {
792791 #[ unstable( feature = "const_raw_ptr_comparison" , issue = "53020" ) ]
793792 #[ rustc_const_unstable( feature = "const_raw_ptr_comparison" , issue = "53020" ) ]
794793 #[ inline]
795- pub const fn guaranteed_eq ( self , other : * const T ) -> bool
794+ pub const fn guaranteed_eq ( self , other : * const T ) -> Option < bool >
796795 where
797796 T : Sized ,
798797 {
799- intrinsics:: ptr_guaranteed_eq ( self , other)
798+ match intrinsics:: ptr_guaranteed_cmp ( self as _ , other as _ ) {
799+ 2 => None ,
800+ other => Some ( other == 1 ) ,
801+ }
800802 }
801803
802- /// Returns whether two pointers are guaranteed to be unequal .
804+ /// Returns whether two pointers are guaranteed to be inequal .
803805 ///
804- /// At runtime this function behaves like `self != other`.
806+ /// At runtime this function behaves like `Some( self == other) `.
805807 /// However, in some contexts (e.g., compile-time evaluation),
806- /// it is not always possible to determine the inequality of two pointers, so this function may
807- /// spuriously return `false ` for pointers that later actually turn out to be unequal .
808- /// But when it returns `true `, the pointers are guaranteed to be unequal .
808+ /// it is not always possible to determine inequality of two pointers, so this function may
809+ /// spuriously return `None ` for pointers that later actually turn out to have its inequality known .
810+ /// But when it returns `Some `, the pointers' inequality is guaranteed to be known .
809811 ///
810- /// This function is the mirror of [`guaranteed_eq`], but not its inverse. There are pointer
811- /// comparisons for which both functions return `false`.
812- ///
813- /// [`guaranteed_eq`]: #method.guaranteed_eq
814- ///
815- /// The return value may change depending on the compiler version and unsafe code must not
812+ /// The return value may change from `Some` to `None` and vice versa depending on the compiler
813+ /// version and unsafe code must not
816814 /// rely on the result of this function for soundness. It is suggested to only use this function
817- /// for performance optimizations where spurious `false ` return values by this function do not
815+ /// for performance optimizations where spurious `None ` return values by this function do not
818816 /// affect the outcome, but just the performance.
819817 /// The consequences of using this method to make runtime and compile-time code behave
820818 /// differently have not been explored. This method should not be used to introduce such
@@ -823,11 +821,14 @@ impl<T: ?Sized> *const T {
823821 #[ unstable( feature = "const_raw_ptr_comparison" , issue = "53020" ) ]
824822 #[ rustc_const_unstable( feature = "const_raw_ptr_comparison" , issue = "53020" ) ]
825823 #[ inline]
826- pub const fn guaranteed_ne ( self , other : * const T ) -> bool
824+ pub const fn guaranteed_ne ( self , other : * const T ) -> Option < bool >
827825 where
828826 T : Sized ,
829827 {
830- intrinsics:: ptr_guaranteed_ne ( self , other)
828+ match self . guaranteed_eq ( other) {
829+ None => None ,
830+ Some ( eq) => Some ( !eq) ,
831+ }
831832 }
832833
833834 /// Calculates the offset from a pointer (convenience for `.offset(count as isize)`).
0 commit comments