External Publication
Visit Post

For structs that have fields that have only one possible representation, enums should use that field as the discriminant

Rust Internals [Unofficial] June 7, 2026
Source

Unfortunately it doesn't work, because the extra bits are padding bits, and padding bits are not guaranteed to be preserved. Consider some code taking &mut Foo and writes a Foo { ... } into it, it may override those bits.

We cannot change this behavior because of existing unsafe code, and we also don't want to change it because it enables optimizations.

There have been discussions about some attribute to preserve padding, but nothing concrete.

Discussion in the ATmosphere

Loading comments...