Since it is possible to transmute between &mut [T]
and &[Cell<T>]
but arguably that is a special case since [T]
is a "pointer" rather than a struct/enum.
#[repr(C)]
struct A<T>(T);
#[repr(transparent)]
struct B(*const ());
#[repr(transparent)]
struct C(*const ());
transmute::<A<B>, A<*const ()>>;
transmute::<A<C>, A<*const ()>>;
transmute::<A<B>, A<C>>;
I guess if repr(C)
were specified on A
then this would actually be safe since the layout is guaranteed to be the same then. Since I need an enum
I don't believe that would work (though repr(C)
doesn't error/warn on enums it seems).
EDIT: Actually, it seems that repr(C)
is intended to work with non-C-like enums so I annotating with that should be enough to make this sound even in the enum case https://github.com/rust-lang/rfcs/pull/2195 .