Closed jswrenn closed 4 years ago
A struct should not be Transparent if it has a field that is also not Transparent:
Transparent
#[typic::repr(C)] pub struct A(u8); assert_not_impl_any!(A: Transparent); #[typic::repr(C)] pub struct B(pub A); let _: B = 0u8.transmute_into(); // This *should* fail.
However, the correct behavior isn't quite as simple as usual transitive trait derive (e.g., derive(Clone) and derive(Copy)). For instance:
derive
derive(Clone)
derive(Copy)
#[typic::repr(C, u8)] enum Foo { A(pub u8), B(pub u8), } #[typic::repr(C, u8)] enum Bar { A(pub u8), B(pub u8), C(u8) } let _ : Bar = Foo::A(42).transmute_into(); // This *should* work.
To me, this implies that transparency should be part of the layout information at both low and high levels.
A struct should not be
Transparent
if it has a field that is also notTransparent
:However, the correct behavior isn't quite as simple as usual transitive trait
derive
(e.g.,derive(Clone)
andderive(Copy)
). For instance:To me, this implies that transparency should be part of the layout information at both low and high levels.