Open
Description
TransmuteFrom
models 'union transmute', which permits extensions of the trailing padding bytes of Src
during the transmutation to Dst
. This model is implemented by TransmuteFrom::transmute
, which uses a union to perform the transmutation. Essentially:
pub unsafe fn transmute_via_union<Src, Dst>(src: Src) -> Dst {
use core::mem::ManuallyDrop;
#[repr(C)]
union Transmute<Src, Dst> {
src: ManuallyDrop<Src>,
dst: ManuallyDrop<Dst>,
}
let transmute = Transmute {
src: ManuallyDrop::new(src),
};
let dst = transmute.dst;
ManuallyDrop::into_inner(dst)
}
Unfortunately, this long-form implementation might be quite heavy on the optimizer. For example, using ManuallyDrop
can cause memcpy
s and alloca
s that LLVM cannot remove: rust-lang/rust#79914
It would therefore be nice to have a intrinsic version of this that wasn't so dependent on the optimizer. We could either, as @scottmcm suggests, modify transmute_unchecked
to provide these semantics, or we could provide a new intrinsic (e.g., transmute_union
) that provides these semantics.
Metadata
Metadata
Assignees
Labels
No labels