Skip to content

Coercepointee validation for: repr transparent, min no. of fields and non generic pointee type constraint - #4950

Open
wesley-lewis wants to merge 4 commits into
Rust-GCC:masterfrom
wesley-lewis:validate-coercepointee
Open

wesley-lewis wants to merge 4 commits into
Rust-GCC:masterfrom
wesley-lewis:validate-coercepointee

Conversation

@wesley-lewis

Copy link
Copy Markdown

Fixes #4914
Fixes #4915
Fixes #4916

Added validation checks for #[derive(CoercePointee)]:

  • the struct must be repr(transparent)
  • it must have at least one field
  • it must have a type parameter to act as the pointee(applicable when single parameter present), and if there are
    several, exactly one must be marked #[pointee]

Adds error code E0802 for these diagnostics.

For testing:

added following piece to gcc/rust/expand/rust-derive-coerce-pointee.cc in the DeriveCoercePointee::go (Item &item) :

  validate_repr_transparent(item);
  validate_number_of_fields(item);
  validate_non_generic_pointee(item);

Do note that error on the first line of the function has to be commented out.

Run the compiler on the derive coerce pointee test file:

./gcc/crab1 ../gccrs/gcc/testsuite/rust/compile/derive-coerce-pointee1.rs -frust-incomplete-and-experimental-compiler-do-not-use -frust-compat-version=1.84 -frust-debug

The debug log would contain all the errors. For that particular file repr transparent is required and thus the error would point out that.

All the validation checks give the error code E0802 on failure. The content of the error is taken from rustc.

For all 3 tests to fail use the following test file:

#![feature(no_core)]
#![feature(lang_items)]
#![no_core]

#[lang = "sized"]
trait Sized {}

#[derive(CoercePointee)]
struct Floop<T> {
    a: *const T,
}

#[repr(transparent)]
#[derive(CoercePointee)]
struct Bad(usize);

#[derive(CoercePointee)]
struct Bad2();
  • [ X] GCC development requires copyright assignment or the Developer's Certificate of Origin sign-off, see https://gcc.gnu.org/contribute.html or https://gcc.gnu.org/dco.html
  • [X ] Read contributing guidlines
  • [X ] make check-rust passes locally
  • [ X] Run clang-format
  • [ X] Added any relevant test cases to gcc/testsuite/rust/

@wesley-lewis wesley-lewis changed the title Coercepointee validation for: Coercepointee validation for: repr transparent, min no. of fields and non generic pointee type constraint Oct 2, 2026
@dkm

dkm commented Oct 2, 2026

Copy link
Copy Markdown
Member

Hello @wesley-lewis !

I think you need to adjust your commits, their logs are empty :). Look at other commits, but feel free to ask if you need help!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants