Tracking Issue for pointer metadata APIs · Issue #81513 · rust-lang/rust (original) (raw)

This is a tracking issue for the RFC 2580 "Pointer metadata & VTable" (rust-lang/rfcs#2580).
The feature gate for the issue is #![feature(ptr_metadata)].

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

Language-level:

API level:

API bikesheds:

Implementation history

Tracked APIs

Last updated for #81172.

pub trait Pointee { /// One of (), usize, or DynMetadata<dyn SomeTrait> type Metadata; }

pub trait Thin = Pointee<Metadata = ()>;

pub const fn metadata<T: ?Sized>(ptr: *const T) -> ::Metadata {}

pub const fn from_raw_parts<T: ?Sized>(*const impl Thin, ::Metadata) -> *const T {} pub const fn from_raw_parts_mut<T: ?Sized>(*mut impl Thin, ::Metadata) -> *mut T {}

impl<T: ?Sized> NonNull { pub const fn from_raw_parts(NonNull, ::Metadata) -> NonNull {}

/// Convenience for `(ptr.cast(), metadata(ptr))`
pub const fn to_raw_parts(self) -> (NonNull<()>, <T as Pointee>::Metadata) {}

}

impl<T: ?Sized> *const T { pub const fn to_raw_parts(self) -> (*const (), ::Metadata) {} }

impl<T: ?Sized> *mut T { pub const fn to_raw_parts(self) -> (*mut (), ::Metadata) {} }

/// <dyn SomeTrait as Pointee>::Metadata == DynMetadata<dyn SomeTrait> pub struct DynMetadata<Dyn: ?Sized> { // Private pointer to vtable }

impl<Dyn: ?Sized> DynMetadata { pub fn size_of(self) -> usize {} pub fn align_of(self) -> usize {} pub fn layout(self) -> crate::alloc::Layout {} }

unsafe impl<Dyn: ?Sized> Send for DynMetadata {} unsafe impl<Dyn: ?Sized> Sync for DynMetadata {} impl<Dyn: ?Sized> Debug for DynMetadata {} impl<Dyn: ?Sized> Unpin for DynMetadata {} impl<Dyn: ?Sized> Copy for DynMetadata {} impl<Dyn: ?Sized> Clone for DynMetadata {} impl<Dyn: ?Sized> Eq for DynMetadata {} impl<Dyn: ?Sized> PartialEq for DynMetadata {} impl<Dyn: ?Sized> Ord for DynMetadata {} impl<Dyn: ?Sized> PartialOrd for DynMetadata {} impl<Dyn: ?Sized> Hash for DynMetadata {}