-
Notifications
You must be signed in to change notification settings - Fork 59
Resolve layout of single variant enums #159
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
Conversation
82e66dc
to
0ecb9d2
Compare
What about |
AFAICT |
To elaborate: users of non-exhaustive enums can't rely on the number of variants not changing under their feet, so for their purposes this part of the UCG would not guarantee anything about the layout of the non-exhaustive enum, since it is not guaranteed to meet the precondition (only one variant). Similarly, most guarantees about the layout of structs automatically wouldn't apply to non-exhaustive structs since fields might be added to them. (Within the same crate/module that defines the non-exhaustive enum, it would technically be allowed, though I guess it's a bit fragile to rely on it when you intend to expend the set of variants later.) |
I don't know what value would we add by not allowing such code to rely on the So I think I disagree (you kind of hint things both ways) ? I think that the layout guarantees specified here apply to both Whether that |
I didn't mean to imply layout computation or what reliance on layout is considered UB by the Rust language should be affected by non_exhaustive. I was just speaking of contracts between libraries: an external library that assumes for soundness that a non_exhaustive struct or enum has a certain layout (based on information that is strictly ) is just as wrong as if it relies on private fields or other information not part of the API. As we both noted, code within the same API boundary as the non-exhaustive type is not subject to the same restrictions. |
Such a library is ugly, brittle, non-portable (to different library versions / toolchain), etc. but it is only wrong if its assumptions are incorrect. If a Rust library exposes a Ideally, nobody would ever need to do this, and such APIs are obviously bad, but doing this types of things is the bread and butter of, for example, the I don't think we can do much about this either. Making a type public leaks its layout, and while features like |
The file says at the beginning that we try to mark what is RFC'ed and what not. Should these new sections get such comments? |
They probably should, I'll add that these sections have not gone through the RFC process, although the other sections more explicitly call what has gone through the process. Before turning the reference or a subset of it into an RFC, we are going to have to do multiple rounds of making everything consistent, and that will include deciding to call out either what has been RFC'ed already, what hasn't, or both. As layout has shown, some of the fundamental definitions evolve over time as we work through newer topics like validity. Each time they change, we kind of have to go through everything. |
cf9647e
to
11b6c4d
Compare
I think all issues have been resolved. Please take a look. |
I've recorded the proposal for multi-variant enums with one inhabited variant in the tracking issue: #79 (comment) |
Addresses part of rust-lang#79 .
11b6c4d
to
e80b69d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with the nit resolved.
Co-Authored-By: Ralf Jung <[email protected]>
@RalfJung nit resolved |
@rkruppe was the merge here fine with you? (Your last comment in this PR was quite a while ago.) |
Yes! |
Addresses part of #79. Addresses part of #37 .
I don't see any reasons not to guarantee this, and AFAICT nobody has mentioned any either.
EDIT: Note that this doesn't say anything about the layout of enums without variants, or where all variants are uninhabited. That should better be tackled in a different PR.