Niche optimization makes use of niches, but padding bytes are neglected

I don't think that's going to happen, because it's a pretty drastic change to what it means to use a type, and it would make a whole bunch of plausible proc macros no longer sound.

If someone wants a niche in a type, I think it's better to represent that by adding an actual field.

Once can make a

#[repr(u8)] enum ZeroByte { Zero = 0 }

and add a field of that type, and the niche optimizations will start to happen.

Then by it being a real field, the "this byte needs to be zero" property is a normal consequence of an ordinary validity invariant.

(And obligatory mention of Pre-pre-RFC: syntactic sugar for `Default::default()` - #75 by ekuber that would let such a field be defaulted and thus less annoying to use.)

2 Likes