まずいなあ。自分もRocketに実質的にtransmuteを含むコミットを投げてしまっているのだが……
Add conversion methods for `Box<UncasedStr>` by dmizuk · Pull Request #373 · SergioBenitez/Rocket
https://github.com/SergioBenitez/Rocket/pull/373
UncasedStr::new is undefined behavior · Issue #494 · SergioBenitez/Rocket
https://github.com/SergioBenitez/Rocket/issues/494
>Same thing for these transmutes, which all assume #[repr(C)].
>UncasedStr::into_uncased
>Uncased::into_boxed_uncased
あっ、とても申し訳ない
あれ、仮にnewtypeと元の型のメモリレイアウトが違うとすれば、その時は型のサイズが異なるはず(本当か?)だからtransmuteはエラーになるような気がしてきたぞ……うーん
@dmiz たとえば &[T] について (usize, *const T) と (*const T, usize) がありうるし、内部表現の違いとはそういうことなのだろうと解釈しました。
そもそも str や [T] そのものは unsized でサイズは取れないので……
@lo48576 ああ、てっきりstruct内の個々のメンバの型についてはメモリレイアウトが勝手に変わることがないと解釈していましたが、よく考えるとそれもはっきりとは保証されていないですね……