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 ! (
@@ -170,7 +171,7 @@ impl Repr {
170
171
pub ( super ) fn new_simple ( kind : ErrorKind ) -> Self {
171
172
let utagged = ( ( kind as usize ) << 32 ) | TAG_SIMPLE ;
172
173
// 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 ( ) ) } ) ;
174
+ let res = Self ( unsafe { NonNull :: new_unchecked ( utagged as * mut ( ) ) } , PhantomData ) ;
174
175
// quickly smoke-check we encoded the right thing (This generally will
175
176
// only run in libstd's tests, unless the user uses -Zbuild-std)
176
177
debug_assert ! (
@@ -184,7 +185,7 @@ impl Repr {
184
185
#[ inline]
185
186
pub ( super ) const fn new_simple_message ( m : & ' static SimpleMessage ) -> Self {
186
187
// Safety: References are never null.
187
- Self ( unsafe { NonNull :: new_unchecked ( m as * const _ as * mut ( ) ) } )
188
+ Self ( unsafe { NonNull :: new_unchecked ( m as * const _ as * mut ( ) ) } , PhantomData )
188
189
}
189
190
190
191
#[ inline]
0 commit comments