GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gccrs

gccrs: Validate pointee field selection for CoercePointee

Enhances validation in gccrs for structs deriving CoercePointee, ensuring a valid pointee field is selected.

This commit adds a validation check to GCC’s Rust front-end for structs that derive CoercePointee. It ensures that such structs have at least one non-generic typed field to serve as the pointee. If multiple non-generic fields are present, the one explicitly marked with the #[pointee] attribute is chosen. This change addresses issues with selecting the correct pointee when no explicit marker is used or when no suitable field exists.

In Details

The gccrs expansion logic for derive-coerce-pointee.cc now includes validate_non_generic_pointee. This function checks that a struct intended for CoercePointee derivation has a suitable field to act as the pointee. It mandates at least one non-generic field and correctly handles cases with multiple non-generic fields by prioritizing the #[pointee] attribute, aligning with Rust's expectations for such structures.

For Context
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.
pointee
In the context of Rust's CoercePointee derive macro, this refers to the specific field within a struct that represents the target type for a coercion operation, often acting like the value a pointer would dereference to.
#[pointee]
An attribute used in Rust code (within gccrs) to explicitly mark a struct field as the 'pointee' when deriving CoercePointee.
type parameter
A placeholder for a type in Rust generics. In this context, a non-generic typed field is one not dependent on type parameters.
Filed Under: gccrsrustvalidationderive macroffi