105
105
use super :: { Custom , ErrorData , ErrorKind , SimpleMessage } ;
106
106
use alloc:: boxed:: Box ;
107
107
use core:: mem:: { align_of, size_of} ;
108
- use core:: ptr:: NonNull ;
108
+ use core:: ptr:: { self , NonNull } ;
109
109
110
110
// The 2 least-significant bits are used as tag.
111
111
const TAG_MASK : usize = 0b11 ;
@@ -126,7 +126,7 @@ impl Repr {
126
126
let p = Box :: into_raw ( b) . cast :: < u8 > ( ) ;
127
127
// Should only be possible if an allocator handed out a pointer with
128
128
// wrong alignment.
129
- debug_assert_eq ! ( ( p as usize & TAG_MASK ) , 0 ) ;
129
+ debug_assert_eq ! ( ( p. addr ( ) & TAG_MASK ) , 0 ) ;
130
130
// Note: We know `TAG_CUSTOM <= size_of::<Custom>()` (static_assert at
131
131
// end of file), and both the start and end of the expression must be
132
132
// valid without address space wraparound due to `Box`'s semantics.
@@ -156,7 +156,7 @@ impl Repr {
156
156
pub ( super ) fn new_os ( code : i32 ) -> Self {
157
157
let utagged = ( ( code as usize ) << 32 ) | TAG_OS ;
158
158
// Safety: `TAG_OS` is not zero, so the result of the `|` is not 0.
159
- let res = Self ( unsafe { NonNull :: new_unchecked ( utagged as * mut ( ) ) } ) ;
159
+ let res = Self ( unsafe { NonNull :: new_unchecked ( ptr :: invalid_mut ( utagged ) ) } ) ;
160
160
// quickly smoke-check we encoded the right thing (This generally will
161
161
// only run in libstd's tests, unless the user uses -Zbuild-std)
162
162
debug_assert ! (
@@ -170,7 +170,7 @@ impl Repr {
170
170
pub ( super ) fn new_simple ( kind : ErrorKind ) -> Self {
171
171
let utagged = ( ( kind as usize ) << 32 ) | TAG_SIMPLE ;
172
172
// Safety: `TAG_SIMPLE` is not zero, so the result of the `|` is not 0.
173
- let res = Self ( unsafe { NonNull :: new_unchecked ( utagged as * mut ( ) ) } ) ;
173
+ let res = Self ( unsafe { NonNull :: new_unchecked ( ptr :: invalid_mut ( utagged ) ) } ) ;
174
174
// quickly smoke-check we encoded the right thing (This generally will
175
175
// only run in libstd's tests, unless the user uses -Zbuild-std)
176
176
debug_assert ! (
@@ -228,7 +228,7 @@ unsafe fn decode_repr<C, F>(ptr: NonNull<()>, make_custom: F) -> ErrorData<C>
228
228
where
229
229
F : FnOnce ( * mut Custom ) -> C ,
230
230
{
231
- let bits = ptr. as_ptr ( ) as usize ;
231
+ let bits = ptr. as_ptr ( ) . addr ( ) ;
232
232
match bits & TAG_MASK {
233
233
TAG_OS => {
234
234
let code = ( ( bits as i64 ) >> 32 ) as i32 ;
0 commit comments