Skip to content

Commit a99a44b

Browse files
authored
Rollup merge of rust-lang#143341 - Manishearth:from-raw-parts-ptr-cast, r=samueltardieu
Mention that casting to *const () is a way to roundtrip with from_raw_parts See discussion on rust-lang#81513
2 parents 78b966c + 2a11a27 commit a99a44b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

core/src/ptr/metadata.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ pub const fn metadata<T: PointeeSized>(ptr: *const T) -> <T as Pointee>::Metadat
106106
/// For slices, see the documentation of [`slice::from_raw_parts`] for safety requirements.
107107
/// For trait objects, the metadata must come from a pointer to the same underlying erased type.
108108
///
109+
/// If you are attempting to deconstruct a DST in a generic context to be reconstructed later,
110+
/// a thin pointer can always be obtained by casting `*const T` to `*const ()`.
111+
///
109112
/// [`slice::from_raw_parts`]: crate::slice::from_raw_parts
110113
#[unstable(feature = "ptr_metadata", issue = "81513")]
111114
#[inline]

0 commit comments

Comments
 (0)