@@ -167,6 +167,12 @@ unsafe impl Pointee for std::ffi::OsStr {
167
167
type Metadata = usize ;
168
168
}
169
169
170
+ /// Pointers to types implementing this trait alias are “thin”.
171
+ ///
172
+ /// This includes statically-Sized types and extern types.
173
+ pub trait Thin : Pointee < Metadata = ( ) > { }
174
+ impl < T : Pointee < Metadata = ( ) > > Thin for T { }
175
+
170
176
/// Returns the metadata of the given pointer.
171
177
///
172
178
/// `*mut T`, `&T`, and `&mut T` can all be passed directly to this function as
@@ -227,7 +233,7 @@ pub const fn to_raw_parts_mut<T: Pointee + ?Sized>(
227
233
/// [`slice::from_raw_parts`]: core::slice::from_raw_parts
228
234
#[ inline]
229
235
pub const fn from_raw_parts < T : Pointee + ?Sized > (
230
- data_address : * const ( ) ,
236
+ data_address : * const impl Thin ,
231
237
metadata : <T as Pointee >:: Metadata ,
232
238
) -> * const T {
233
239
// SAFETY: Accessing the value from the `PtrRepr` union is safe since
@@ -236,7 +242,7 @@ pub const fn from_raw_parts<T: Pointee + ?Sized>(
236
242
unsafe {
237
243
PtrRepr {
238
244
components : PtrComponents {
239
- data_address,
245
+ data_address : data_address . cast ( ) ,
240
246
metadata,
241
247
} ,
242
248
}
@@ -249,7 +255,7 @@ pub const fn from_raw_parts<T: Pointee + ?Sized>(
249
255
/// See [`from_raw_parts`] for more details.
250
256
#[ inline]
251
257
pub const fn from_raw_parts_mut < T : Pointee + ?Sized > (
252
- data_address : * mut ( ) ,
258
+ data_address : * mut impl Thin ,
253
259
metadata : <T as Pointee >:: Metadata ,
254
260
) -> * mut T {
255
261
// SAFETY: Accessing the value from the `PtrRepr` union is safe since
@@ -258,7 +264,7 @@ pub const fn from_raw_parts_mut<T: Pointee + ?Sized>(
258
264
unsafe {
259
265
PtrRepr {
260
266
components : PtrComponents {
261
- data_address,
267
+ data_address : data_address . cast ( ) ,
262
268
metadata,
263
269
} ,
264
270
}
0 commit comments