gccrs: Improve struct field count checking for coerce-pointee
Fixes a bug in gccrs where struct field counts were not correctly differentiated for derive CoercePointee.
This commit refines the field count validation for structs deriving CoercePointee in GCC’s Rust front-end. It introduces a virtual get_field_count method to the AST::Struct class to correctly distinguish between StructStruct and TupleStruct types. This ensures accurate checking of field counts, preventing potential errors in the derive macro expansion.
In Details
Within gccrs, the derive-coerce-pointee.cc expansion logic needed to correctly ascertain the number of fields in a struct for the CoercePointee derive macro. Previously, checking Item::Kind::Struct was insufficient. This patch adds a virtual get_field_count to AST::Struct, implemented by its derived classes StructStruct and TupleStruct, to provide an accurate count. This ensures the validation logic in validate_number_of_fields operates correctly on the Abstract Syntax Tree representation.
- gccrs
- The Rust front-end for the GCC compiler suite, enabling GCC to compile Rust code.
- 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.
- AST::Struct
- Represents a struct node within GCC's Abstract Syntax Tree for Rust code.
- StructStruct
- A type of struct in Rust (and represented in gccrs' AST) that uses named fields.
- TupleStruct
- A type of struct in Rust (and represented in gccrs' AST) that uses anonymous, ordered fields.