Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The seemingly contradictory #[repr(Rust, C)] is allowed #116825

Closed
fmease opened this issue Oct 16, 2023 · 4 comments
Closed

The seemingly contradictory #[repr(Rust, C)] is allowed #116825

fmease opened this issue Oct 16, 2023 · 4 comments
Assignees
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-repr Area: the `#[repr(stuff)]` attribute C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Milestone

Comments

@fmease
Copy link
Member

fmease commented Oct 16, 2023

#[repr(Rust)] is already on beta and will soon hit stable.

I just found out that #[repr(C, Rust)] successfully compiles while I expected it to error due to contradictory representations.

Further, I wonder if #[repr(Rust, transparent)] should be allowed? Currently it errors with E0692, transparent struct cannot have other repr hints. (see err's response)

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 16, 2023
@fmease fmease added A-attributes Area: Attributes (`#[…]`, `#![…]`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 16, 2023
@fmease fmease changed the title #[repr(Rust)] and other representations Behavior of #[repr(Rust, OTHER)] Oct 16, 2023
@fmease fmease changed the title Behavior of #[repr(Rust, OTHER)] Behavior of #[repr(Rust, OTHER_REPR_HINT)] Oct 16, 2023
@Mark-Simulacrum Mark-Simulacrum added this to the 1.74.0 milestone Oct 16, 2023
@fmease fmease added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Oct 17, 2023
@fmease fmease self-assigned this Oct 17, 2023
@compiler-errors
Copy link
Member

compiler-errors commented Oct 17, 2023

Seems pretty obvious we should have exactly one repr, and only allow repr modifiers like packed afterwards. (Rust, transparent) seems like it's asking for two mutually exclusive things.

@fmease fmease changed the title Behavior of #[repr(Rust, OTHER_REPR_HINT)] The seemingly contrardirectory #[repr(Rust, C)] is allowed Oct 17, 2023
@fmease fmease changed the title The seemingly contrardirectory #[repr(Rust, C)] is allowed The seemingly contradictory #[repr(Rust, C)] is allowed Oct 17, 2023
@marmeladema
Copy link
Contributor

Should a C-struct be able to contain a Rust-struct ?
Currently the compiler is happy about this kind of construct too: https://play.rust-lang.org/?version=beta&mode=debug&edition=2021&gist=0588a57ac361ed85664914d86cb14060

If not, it might deserve it's own issue?

@workingjubilee
Copy link
Member

That seems kosher to me? It might not be if

#[repr(C)]
pub struct ReprC(ReprRust, ReprRust);

But that's a different matter and has more to do with defining tuples in C being unclear.

fmease added a commit to fmease/rust that referenced this issue Oct 19, 2023
Make `#[repr(Rust)]` incompatible with other (non-modifier) representation hints like `C` and `simd`

Read more about this change here: rust-lang#116829 (comment).

Fixes [after backport] rust-lang#116825.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 19, 2023
Rollup merge of rust-lang#116829 - fmease:rust-aint-c, r=compiler-errors

Make `#[repr(Rust)]` incompatible with other (non-modifier) representation hints like `C` and `simd`

Read more about this change here: rust-lang#116829 (comment).

Fixes [after backport] rust-lang#116825.
@fmease
Copy link
Member Author

fmease commented Oct 21, 2023

Fixed in #116829 and backported in #117005. Closing as completed.

@fmease fmease closed this as completed Oct 21, 2023
@fmease fmease added the A-repr Area: the `#[repr(stuff)]` attribute label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-repr Area: the `#[repr(stuff)]` attribute C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants