The documentation of UnOp::PtrMetadata (which we lower to ProjectionElem::PtrMetadata) specifies that the output of the operation for a &dyn Trait place is a ptr::DynMetadata, which is defined as:
#[lang = "dyn_metadata"]
pub struct DynMetadata<Dyn: PointeeSized> {
_vtable_ptr: NonNull<VTable>,
_phantom: crate::marker::PhantomData<Dyn>,
}
This is also how the compiler types the operator, of course. Compiling core::ptr::metadata(&42 as &dyn std::fmt::Display) with --monomorphize --extract-opaque-bodies gives us
// Full name: core::ptr::metadata::metadata::<(dyn Display)>
pub fn metadata::<(dyn Display)>(ptr_1: *const (dyn Display)) -> DynMetadata::<(dyn Display)>
{
let _0: DynMetadata::<(dyn Display)>; // return
let ptr_1: *const (dyn Display + '0); // arg #1
_0 = copy ptr_1.metadata
return
}
However we ourselves treat this projection as just giving us a pointer; for instance in transform_dyn_trait_calls we just offset the output of that and move it around. This is quite awkward, as this means we have a place projection that has several output types (our fault, tbh).
We should probably fix this by instead translating UnOp::PtrMetadata into a sequence of ProjectionElem::PtrMetadata -> transmute into DynMetadata, and keep treating the projection as just a plain old pointer!
The documentation of
UnOp::PtrMetadata(which we lower toProjectionElem::PtrMetadata) specifies that the output of the operation for a&dyn Traitplace is aptr::DynMetadata, which is defined as:This is also how the compiler types the operator, of course. Compiling
core::ptr::metadata(&42 as &dyn std::fmt::Display)with--monomorphize --extract-opaque-bodiesgives usHowever we ourselves treat this projection as just giving us a pointer; for instance in
transform_dyn_trait_callswe just offset the output of that and move it around. This is quite awkward, as this means we have a place projection that has several output types (our fault, tbh).We should probably fix this by instead translating
UnOp::PtrMetadatainto a sequence ofProjectionElem::PtrMetadata->transmuteintoDynMetadata, and keep treating the projection as just a plain old pointer!