Closed
Description
I'd like to be able to make the assumption that char
is ABI compatible with u32
for some validation code in bytecheck. I have actually been making this assumption for a while and never had problems (including with MIRI), so I think this is de-facto the case. I thought that char
and u32
were supposed to have the same layout but when I went looking I realized I couldn't find anything. As far as I know, it doesn't really make sense for char
s to be anything other than a u32
with fewer valid bit patterns.
For completeness:
- "The Rust Reference: Type layout": States that both
u32
andchar
are four bytes. - "The Rust Reference: Textual types": States that it "is a Unicode scalar value (i.e. a code point that is not a surrogate), represented as a 32-bit unsigned word in the 0x0000 to 0xD7FF or 0xE000 to 0x10FFFF range.". I don't think this can be interpreted as having the same ABI as
u32
.