@@ -82,6 +82,10 @@ const VTABLE_PTR_2: *const () = {
82
82
do_test ! ( 0 as * const u8 , 0 as * const u8 , Some ( true ) ) ;
83
83
do_test ! ( 0 as * const u8 , 1 as * const u8 , Some ( false ) ) ;
84
84
85
+ // Integer-valued pointers can always be compared.
86
+ do_test ! ( 1 as * const u8 , 1 as * const u8 , Some ( true ) ) ;
87
+ do_test ! ( 1 as * const u8 , 2 as * const u8 , Some ( false ) ) ;
88
+
85
89
// Cannot be `None`: `static`s' addresses, references, (and within and one-past-the-end of those),
86
90
// and `fn` pointers cannot be null, and `is_null` is stable with strong guarantees, and
87
91
// `is_null` is implemented using `guaranteed_cmp`.
@@ -93,6 +97,9 @@ do_test!(&(), 0 as *const u8, Some(false));
93
97
do_test ! ( const { & ( ) } , 0 as * const u8 , Some ( false ) ) ;
94
98
do_test ! ( FN_PTR , 0 as * const u8 , Some ( false ) ) ;
95
99
100
+ // This pointer is out-of-bounds, but still cannot be equal to 0 because of alignment.
101
+ do_test ! ( ( & raw const A ) . cast:: <u8 >( ) . wrapping_add( size_of:: <T >( ) + 1 ) , 0 as * const u8 , Some ( false ) ) ;
102
+
96
103
// aside from 0, these pointers might end up pretty much anywhere.
97
104
do_test ! ( & A , align_of:: <T >( ) as * const u8 , None ) ;
98
105
do_test ! ( ( & raw const A ) . wrapping_byte_add( 1 ) , ( align_of:: <T >( ) + 1 ) as * const u8 , None ) ;
@@ -149,9 +156,11 @@ do_test!(&A, (&T(42) as *const T).wrapping_byte_add(1), Some(false));
149
156
do_test ! ( & A , ( const { & T ( 42 ) } as * const T ) . wrapping_byte_add( 1 ) , Some ( false ) ) ;
150
157
do_test ! ( & A , ( { const X : T = T ( 42 ) ; & X } as * const T ) . wrapping_byte_add( 1 ) , Some ( false ) ) ;
151
158
152
- // We could return `Some(false)` here, as pointers to different statics can never be equal if that
153
- // would require the statics to overlap, even if the pointers themselves are offset out of bounds.
154
- // We currently only check strictly in-bounds pointers, however.
159
+ // We could return `Some(false)` for these, as pointers to different statics can never be equal if
160
+ // that would require the statics to overlap, even if the pointers themselves are offset out of
161
+ // bounds or one-past-the-end. We currently only check strictly in-bounds pointers when comparing
162
+ // pointers to different statics, however.
163
+ do_test ! ( ( & raw const A ) . wrapping_add( 1 ) , ( & raw const B ) . wrapping_add( 1 ) , None ) ;
155
164
do_test ! (
156
165
( & raw const LARGE_WORD_ALIGNED ) . cast:: <usize >( ) . wrapping_add( 2 ) ,
157
166
( & raw const MUT_LARGE_WORD_ALIGNED ) . cast:: <usize >( ) . wrapping_add( 1 ) ,
0 commit comments