DuckLogic / rust-static-reflect

Compile time reflection for Rust
MIT License
7 stars 1 forks source link

C-like enums should generate `TypeInfo::CStyleEnum` instead of `TypeInfo::Integer` #2

Open Techcable opened 3 years ago

Techcable commented 3 years ago

Right now, the TypeInfo doesn't accurately reflect the static type of C-style enums.

In Rust, (unlike C), enums can only accept a restricted subset of values. For example, given the enum definition:

#[repr(u32)]
enum Test {
    One = 1,
    Two = 2,
    Three = 4,
}
/*
 * Rust: UNDEFINED BEHAVIOR
 * C: This is fine
 */
std::mem::transmute::<u32, Test>(12)

Right now, Test::TYPE_INFO == u32::TYPE_INFO as if we were using the C representation. This is misleading, and should be fixed to use the new CStyleEnumDef struct that I just added.