Support zero-sized type checking for `repr(transparent)` in gccrs
gccrs now correctly type-checks `#[repr(transparent)]` structs, including zero-sized ones.
gccrs has been updated to properly support type checking for Rust’s #[repr(transparent)] attribute, specifically for zero-sized types (ZSTs). New functions are introduced to determine if a type is zero-sized, and these checks are integrated into the type-checking logic for transparent structs, ensuring correct handling of types like PhantomData within them.
In Details
gccrs enhances its type checking for #[repr(transparent)] by introducing is_zero_sized() methods to various type representations (BaseType, TupleType, ArrayType, ADTType). The TypeCheckItem::visit(StructStruct) is updated to incorporate these checks when analyzing transparently represented structs, particularly ensuring that zero-sized members are handled correctly. The compilation of ADTType for transparent structs with multiple fields is also adjusted.
- gccrs
- The GCC backend for the Rust programming language, enabling Rust code to be compiled by GCC.
- zero-sized type (ZST)
- A type in Rust that occupies no space in memory, such as
()(unit type) orPhantomData. They have size 0 and alignment 0. - repr(transparent)
- A Rust attribute that tells the compiler that a struct with a single field should be represented in memory exactly like its field. This is often used for creating newtype wrappers.
- PhantomData
- A special marker type in Rust used within generic structs to indicate that the struct logically contains a value of a certain type, even if it doesn't physically store it. This is often used to manage variance and lifetimes.
- type checking
- The process by which a compiler verifies that the types used in a program are consistent and adhere to the language's rules.