gccrs: Validate repr(transparent) for CoercePointee structs
Adds validation for `#[repr(transparent)]` structs using the `CoercePointee` derive macro in gccrs.
This commit enhances the GCC Rust compiler’s validation for structs marked with #[repr(transparent)] that also derive CoercePointee. It ensures that such structs adhere to the requirements for transparent representation, particularly concerning their field structure. The change introduces a new validation function validate_repr_transparent and associates it with the E0802 error code, improving the correctness of code generation for these specific Rust constructs.
In Details
The gccrs subsystem now validates Rust structs annotated with #[repr(transparent)] when they also use the CoercePointee derive macro. The validate_repr_transparent function in rust-derive-coerce-pointee.cc enforces specific structural invariants required for transparent types to interoperate correctly with C FFI or other low-level mechanisms. This ensures that the compiler correctly handles the memory layout and type coercion for these specialized structs, preventing potential ABI mismatches or undefined behavior.
- gccrs
- The Rust front-end for the GCC compiler suite, enabling GCC to compile Rust code.
- repr(transparent)
- A Rust attribute that allows a struct containing a single field to be represented in memory exactly like that single field, enabling C compatibility and zero-cost abstractions.
- CoercePointee
- A Rust derive macro (likely custom or for a specific FFI use case within gccrs) that likely assists in coercing types to pointer-like behavior, possibly for FFI or unsafe code contexts.
- derive macro
- A macro in Rust that generates code automatically based on annotations (attributes) on structs, enums, or functions. It runs during compilation.
- E0802
- An error code specific to the GCC Rust front-end (gccrs), indicating an issue related to the
CoercePointeederive macro, likely concerning struct field requirements.