Re:Type-Level Programming in Rust
by chrismorgan on Monday October 05, 2020 @02:36PM
(#24690596)
I knew there was another #[repr(…)] value, just couldn’t remember its name and didn’t look it up. Thanks for pointing it out. Yep, #[repr(transparent)] is a correct way of fixing the undefined behaviour—and if it won’t compile, then #[repr(C)] will do.
I’m pretty sure that declaring both `Item` and `SecureVec` as `#[repr(transparent)]` would cover that last 0.0001% chance: it protects against the extra fields becoming non-zero-size by accident and forces the binary representation to be identical to the first field.
At that point, he’s transmuting between things with the same representation; all that’s left to verify is semantics.