Description
Multiple times recently, while looking at #36799, I have wanted to know exactly how a type is laid out in memory, including padding and unused bytes. Particular for enums where the variants can vary significantly in size, and shrinking large variants can be a win.
I have successfully shrunk some types (#37445, #37577). I manually worked out their memory layouts by using a combination of println!
statements and staring at the code. I can usually work out the layout, though not always. (E.g. I know that Rvalue
is 152 bytes on 64-bit platforms, and that the BinaryOp
and CheckedBinaryOp
variants are the largest, but I haven't yet worked out why they take that much space because the nesting of the types within those variants is deep and non-obvious.)
But it is a huge pain to do it manually, as well as unreliable. It would be lovely if there was an easy way to get this information. Something like std::intrinsics::type_name
, perhaps. Such a feature would have wide utility for developers of many Rust programs.