104
104
105
105
use super :: { Custom , ErrorData , ErrorKind , SimpleMessage } ;
106
106
use alloc:: boxed:: Box ;
107
+ use core:: marker:: PhantomData ;
107
108
use core:: mem:: { align_of, size_of} ;
108
109
use core:: ptr:: NonNull ;
109
110
@@ -115,7 +116,7 @@ const TAG_OS: usize = 0b10;
115
116
const TAG_SIMPLE : usize = 0b11 ;
116
117
117
118
#[ repr( transparent) ]
118
- pub ( super ) struct Repr ( NonNull < ( ) > ) ;
119
+ pub ( super ) struct Repr ( NonNull < ( ) > , PhantomData < ErrorData < Box < Custom > > > ) ;
119
120
120
121
// All the types `Repr` stores internally are Send + Sync, and so is it.
121
122
unsafe impl Send for Repr { }
@@ -145,7 +146,7 @@ impl Repr {
145
146
// box, and `TAG_CUSTOM` just... isn't zero -- it's `0b01`). Therefore,
146
147
// `TAG_CUSTOM + p` isn't zero and so `tagged` can't be, and the
147
148
// `new_unchecked` is safe.
148
- let res = Self ( unsafe { NonNull :: new_unchecked ( tagged) } ) ;
149
+ let res = Self ( unsafe { NonNull :: new_unchecked ( tagged) } , PhantomData ) ;
149
150
// quickly smoke-check we encoded the right thing (This generally will
150
151
// only run in libstd's tests, unless the user uses -Zbuild-std)
151
152
debug_assert ! ( matches!( res. data( ) , ErrorData :: Custom ( _) ) , "repr(custom) encoding failed" ) ;
@@ -156,7 +157,7 @@ impl Repr {
156
157
pub ( super ) fn new_os ( code : i32 ) -> Self {
157
158
let utagged = ( ( code as usize ) << 32 ) | TAG_OS ;
158
159
// 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 ( ) ) } ) ;
160
+ let res = Self ( unsafe { NonNull :: new_unchecked ( utagged as * mut ( ) ) } , PhantomData ) ;
160
161
// quickly smoke-check we encoded the right thing (This generally will
161
162
// only run in libstd's tests, unless the user uses -Zbuild-std)
162
163
debug_assert ! (
@@ -171,7 +172,7 @@ impl Repr {
171
172
pub ( super ) fn new_simple ( kind : ErrorKind ) -> Self {
172
173
let utagged = ( ( kind as usize ) << 32 ) | TAG_SIMPLE ;
173
174
// Safety: `TAG_SIMPLE` is not zero, so the result of the `|` is not 0.
174
- let res = Self ( unsafe { NonNull :: new_unchecked ( utagged as * mut ( ) ) } ) ;
175
+ let res = Self ( unsafe { NonNull :: new_unchecked ( utagged as * mut ( ) ) } , PhantomData ) ;
175
176
// quickly smoke-check we encoded the right thing (This generally will
176
177
// only run in libstd's tests, unless the user uses -Zbuild-std)
177
178
debug_assert ! (
@@ -185,7 +186,7 @@ impl Repr {
185
186
#[ inline]
186
187
pub ( super ) const fn new_simple_message ( m : & ' static SimpleMessage ) -> Self {
187
188
// Safety: References are never null.
188
- Self ( unsafe { NonNull :: new_unchecked ( m as * const _ as * mut ( ) ) } )
189
+ Self ( unsafe { NonNull :: new_unchecked ( m as * const _ as * mut ( ) ) } , PhantomData )
189
190
}
190
191
191
192
#[ inline]
0 commit comments