-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
repr(transparent) could accept singleton ZST with alignment > 1. #100954
Comments
Nominating for discussion at lang team meeting.
@rustbot label: +I-lang-nominated |
I think this formulation makes it not at all clear that alignment matters. I would just say, it can have at most one field that is not a 1-ZST. (Also Cc #96921) |
Yeah, and it is possible to construct |
I think this rule makes the most sense to me. After all, as you said, one can do #[repr(transparent)]
struct Rtemp<const N: usize>([usize; N]);
type R = Rtemp<0>; which I think is fine. Or, more generally, I think that |
Discussed in lang-team meeting to general happiness and accord. Based on current attendance (not everyone), we would welcome a PR implementing this change and we could FCP that PR to confirm. An alternate phrasing of the rule is:
|
@tmandry proposes: "You can have at most one field in your struct, ignoring any 1-ZST fields." |
Anything that doesn't include a double negative works for me :P |
I was going to add an induction definition (one-field is fine; adding 1-ZST fields is fine), but it turns out that this is legal: #[repr(transparent)]
struct Foo {} Which means that the current rule isn't actually
And thus I'm even more in favour of the "at most one" version of the rule, since that seems to be what we're already doing in other situations. |
removing nomination; we discussed this last week. @rustbot label: -I-lang-nominated |
Somewhere along the way, this was done, as the code in the description is accepted now. |
And there's an existing test for it here: rust/tests/ui/repr/repr-transparent.rs Lines 44 to 45 in 5572759
|
I tried this code:
I expected to see this happen: That code could be accepted.
Instead, this happened: The code is rejected, with the diagnostic:
That is, we could loosen the
repr(transparent)
rules to say that it "requires at most one field that occupies memory"; this is a loosening of our current rules on two levels:repr(transparent)
structHat tip to @RalfJung for pointing this oddity out as part of PR #99972
The text was updated successfully, but these errors were encountered: