For structs that have fields that have only one possible representation, enums should use that field as the discriminant
Rust Internals [Unofficial]
June 8, 2026
I think you have misunderstood the example. Given the repr(C) and repr(u8) layout rules, the struct Foo is guaranteed to have 0x01 stored at offset 3, and the struct Bar is guaranteed to have 0x02 stored at offset 3. Any value which does not meet one of these conditions is not a valid value of Foo or Bar. Thus, neither an &mut Foo nor an &mut FooDiscriminant may be used to write any byte other than a 0x01 at offset 3, so the enum FooBar could use that byte as its discriminant.
This is a possible layout optimization, but the compiler does not currently support it. It is similar to the case of wanting to collapse two non-overlapping enums:
#[repr(u8)]
#[derive(Clone, Copy)]
enum Foo {
F1 = 1,
F2 = 2,
}
#[repr(u8)]
#[derive(Clone, Copy)]
enum Bar {
B3 = 3,
B4 = 4,
}
enum FooBar {
Foo(Foo),
Bar(Bar),
}
This could be stored as one byte, but is not (yet).
Discussion in the ATmosphere