Closed
Description
Here's a few things I thought of while reading the docs:
- The term
type punning
is used without being defined. Ordinarily, I wouldn't complain about this because it's very easy to Google search but most of the search results on the first page say that type punning is undefined behavior (in C\C++). This doesn't appear to be true in Rust because the Undefined Behaviors Page only references LLVM's pointer aliasing rules which seem to indicate that TBAA doesn't apply.- It would probably be a good idea to give a short definition of the term and state that it is (or is not) undefined behavior in Rust.
~~~ - Having an explicit reason stated as to why it's UB would help the reader figure out if the same rule applies to what they are trying to do.~~~
- Another common use of type punning in C is to take a set of bytes (perhaps read off disk or the network) and then cast them into a `struct` of the same size.
- I think this is an allowed usage of `transmute()` provided the struct is `repr(C)`. Having an example that shows how to do this correctly and also discusses the potential issues such as relying on the endianness being the same would be helpful. If this isn't allowed, then stating that would also be useful.