Skip to content

Conversation

@Pasta-coder
Copy link
Contributor

The #[repr] attribute is only valid for structs, enums, and unions. Applying it to a function is invalid and should result in an error. This patch adds a check in the attribute visitor to reject #[repr] on functions, matching rustc behavior.

Fixes #4232

gcc/rust/ChangeLog:

* util/rust-attributes.cc: Emit error for #[repr] on functions.

gcc/testsuite/ChangeLog:

* rust/compile/repr_on_function.rs: New test.

@Pasta-coder Pasta-coder force-pushed the fix/repr-invalid-4232 branch from c1894f9 to 534d601 Compare January 4, 2026 08:35
@Pasta-coder Pasta-coder marked this pull request as draft January 6, 2026 13:26
@Pasta-coder
Copy link
Contributor Author

drafted to resolve conflicts

@Pasta-coder Pasta-coder force-pushed the fix/repr-invalid-4232 branch 2 times, most recently from 98a508e to 3c307f9 Compare January 7, 2026 19:58
@Pasta-coder Pasta-coder marked this pull request as ready for review January 7, 2026 21:08
The #[repr] attribute is only valid for structs, enums, and unions.
Applying it to a function is invalid and should result in an error.
This patch adds a check in the attribute visitor to reject #[repr]
on functions, matching rustc behavior.

Fixes Rust-GCC#4232

gcc/rust/ChangeLog:

	* util/rust-attributes.cc (AttributeChecker::check_attributes): Emit error for #[repr].

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4232.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix/repr-invalid-4232 branch from 3c307f9 to cc80c7f Compare January 13, 2026 08:11
@Pasta-coder
Copy link
Contributor Author

@P-E-P please review .

thankyou .

@P-E-P P-E-P added this pull request to the merge queue Jan 13, 2026
Merged via the queue into Rust-GCC:master with commit a23b621 Jan 13, 2026
12 checks passed
@Pasta-coder Pasta-coder deleted the fix/repr-invalid-4232 branch January 13, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

repr attribute should give error when applied to other than struct enum or union

2 participants