nail down the final validity rules: references and unions - #2337
nail down the final validity rules: references and unions#2337RalfJung wants to merge 2 commits into
Conversation
|
@rustbot label +I-lang-nominated |
75ee1eb to
caf7145
Compare
caf7145 to
93d25cc
Compare
|
A proposal came up in rust-lang/unsafe-code-guidelines#620 to slightly strengthen the requirements for references / @scottmcm do you have suggestions for how that should be worded? |
| For unsized types, this check considers dynamic information from the metadata: | ||
| If `T` has an unsized tail of slice type (`[U]`), it is inhabited of the length encoded in the metadata is 0 or if `U` is inhabited. |
There was a problem hiding this comment.
These two lines are for rust-lang/unsafe-code-guidelines#620. We didn't explicitly discuss this case in the opsem FCP.
a094ac6 to
7aec9f3
Compare
7aec9f3 to
c8ce01e
Compare
I don't have anything concrete. At least as a mental model -- whether it can be phrased well for a reference I'm less sure -- I wonder if there's a general rule here like saying that the type in the reference must, including looking at the metadata, represent a well-formed and inhabited type. (Part of me wants to say it comes from an unsizing, but there's nothing to unsize to a Basically I wish the "length has to be zero for uninhabited elements" and "length bound for non-ZST elements is |
|
So what do you think about the wording I put in this PR? |
|
@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns. |
|
I reviewed the proposed rules both for unions and for references, and this looks reasonable to me. @rfcbot reviewed |
|
This makes me want a separate language construct for "no, I'm not doing partial overwrite silliness" because this rule has meant that unions are not usable for the cases I wanted, but if this is the right answer for FFI unions and such then so be it. @rfcbot reviewed |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
FWIW the unsized type part hasn't been FCP'd by us yet, as mentioned above. We can do that in a separate issue or a joint FCP here. |
This translates the following t-opsem FCPs into Reference text:
Cc @rust-lang/opsem
@rust-lang/lang you have not FCP'd this yet; please let us know if you want this to go through your own decision process as well.
Fixes rust-lang/unsafe-code-guidelines#413
Fixes rust-lang/unsafe-code-guidelines#414
Fixes rust-lang/unsafe-code-guidelines#438