@@ -36,7 +36,10 @@ impl<T: ?Sized> *const T {
36
36
pub const fn is_null ( self ) -> bool {
37
37
// Compare via a cast to a thin pointer, so fat pointers are only
38
38
// 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
+ }
40
43
}
41
44
42
45
/// Casts to a pointer of another type.
@@ -770,20 +773,16 @@ impl<T: ?Sized> *const T {
770
773
771
774
/// Returns whether two pointers are guaranteed to be equal.
772
775
///
773
- /// At runtime this function behaves like `self == other`.
776
+ /// At runtime this function behaves like `Some( self == other) `.
774
777
/// However, in some contexts (e.g., compile-time evaluation),
775
778
/// 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.
781
781
///
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
785
784
/// 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
787
786
/// affect the outcome, but just the performance.
788
787
/// The consequences of using this method to make runtime and compile-time code behave
789
788
/// differently have not been explored. This method should not be used to introduce such
@@ -792,29 +791,28 @@ impl<T: ?Sized> *const T {
792
791
#[ unstable( feature = "const_raw_ptr_comparison" , issue = "53020" ) ]
793
792
#[ rustc_const_unstable( feature = "const_raw_ptr_comparison" , issue = "53020" ) ]
794
793
#[ inline]
795
- pub const fn guaranteed_eq ( self , other : * const T ) -> bool
794
+ pub const fn guaranteed_eq ( self , other : * const T ) -> Option < bool >
796
795
where
797
796
T : Sized ,
798
797
{
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
+ }
800
802
}
801
803
802
- /// Returns whether two pointers are guaranteed to be unequal .
804
+ /// Returns whether two pointers are guaranteed to be inequal .
803
805
///
804
- /// At runtime this function behaves like `self != other`.
806
+ /// At runtime this function behaves like `Some( self == other) `.
805
807
/// 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 .
809
811
///
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
816
814
/// 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
818
816
/// affect the outcome, but just the performance.
819
817
/// The consequences of using this method to make runtime and compile-time code behave
820
818
/// differently have not been explored. This method should not be used to introduce such
@@ -823,11 +821,14 @@ impl<T: ?Sized> *const T {
823
821
#[ unstable( feature = "const_raw_ptr_comparison" , issue = "53020" ) ]
824
822
#[ rustc_const_unstable( feature = "const_raw_ptr_comparison" , issue = "53020" ) ]
825
823
#[ inline]
826
- pub const fn guaranteed_ne ( self , other : * const T ) -> bool
824
+ pub const fn guaranteed_ne ( self , other : * const T ) -> Option < bool >
827
825
where
828
826
T : Sized ,
829
827
{
830
- intrinsics:: ptr_guaranteed_ne ( self , other)
828
+ match self . guaranteed_eq ( other) {
829
+ None => None ,
830
+ Some ( eq) => Some ( !eq) ,
831
+ }
831
832
}
832
833
833
834
/// Calculates the offset from a pointer (convenience for `.offset(count as isize)`).
0 commit comments