-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Change untagged_unions to not allow union fields with drop #56440
Conversation
r? @estebank (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
4f96685
to
f54b599
Compare
I'd suggest we change the behavior of the feature gate only. So behavior of stable does not change, but we can test on nightly how these unions behave (e.g. the behavior of drop on assignment and the initialization checker might have to be tweaked to match the RFC). My expectation would be that nightly with the |
@RalfJung That makes sense, so we'd make a breaking change for that feature gate. In that case there should definitely be a suggestion to use ManuallyDrop as a diagnostic too. |
@nikomatsakis Any thoughts on what the correct place in the code is for this, a check union fields don't need dropping? |
@bluss I think this check would make sense to do in this function rust/src/librustc_typeck/check/mod.rs Lines 1303 to 1312 in 8375ab4
|
baf438f
to
916aea3
Compare
Ok, updated with the new rule:
I've fixed tests quickly but with the best sense I had, so those could require ideas in review. |
E0720: r##" | ||
A `union` can not have fields with destructors. | ||
"##, | ||
|
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.
Do we have a system for assigning error numbers? Yes, the text is a bit lacking here.
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.
We do not really have a system, no. You just pick one.
|
||
let mut u3 = U3 { a: ManuallyDrop::new(String::from("old")) }; // OK | ||
u3.a = ManuallyDrop::new(String::from("new")); //~ ERROR assignment to non-`Copy` union | ||
*u3.a = String::from("new"); //~ ERROR access to union field is unsafe |
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.
(Above 7 lines).
The different rules between ManuallyDrop<i32>
vs ManuallyDrop<String>
are a bit confusing, but due to the Copy/non-Copy distinction.
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.
To be clear, this distinction is pre-existing, right? Or are you referring to some behavior that this RFC introduced?
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
fe61c8b
to
19f7852
Compare
For now, part of unstable feature untagged_unions.
e14bce6
to
87c66a8
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
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.
So -- code seems good now, but the test still is not pasing
Sure, I wasn't sure about when to request a new smallvec release, but I've done so now. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The ICE reproduces locally, same message as #57156 and a smallvec in the backtrace, but will have to look closer at it. ICE backtrace
|
☔ The latest upstream changes (presumably #57805) made this pull request unmergeable. Please resolve the merge conflicts. |
Ping from triage @bluss: What is the status of this PR? |
ping from triage @bluss any updates on this? |
ping from triage @bluss |
…tsakis Updates smallvec and new_debug_unreachable The version `0.6.10` of smallvec has released that fixes an [ICE](rust-lang#61549). This is re-submission of rust-lang#58773. And this may let rust-lang#56440 re-start.
…tsakis Updates smallvec and new_debug_unreachable The version `0.6.10` of smallvec has released that fixes an [ICE](rust-lang#61549). This is re-submission of rust-lang#58773. And this may let rust-lang#56440 re-start.
…tsakis Updates smallvec and new_debug_unreachable The version `0.6.10` of smallvec has released that fixes an [ICE](rust-lang#61549). This is re-submission of rust-lang#58773. And this may let rust-lang#56440 re-start.
… r=RalfJung Change untagged_unions to not allow union fields with drop This is a rebase of rust-lang#56440, massaged to solve merge conflicts and make the test suite pass. Change untagged_unions to not allow union fields with drop Union fields may now never have a type with attached destructor. This for example allows unions to use arbitrary field types only by wrapping them in `ManuallyDrop` (or similar). The stable rule remains, that union fields must be `Copy`. We use the new rule for the `untagged_union` feature. Tracking issue: rust-lang#55149
… r=RalfJung Change untagged_unions to not allow union fields with drop This is a rebase of rust-lang#56440, massaged to solve merge conflicts and make the test suite pass. Change untagged_unions to not allow union fields with drop Union fields may now never have a type with attached destructor. This for example allows unions to use arbitrary field types only by wrapping them in `ManuallyDrop` (or similar). The stable rule remains, that union fields must be `Copy`. We use the new rule for the `untagged_union` feature. Tracking issue: rust-lang#55149
Change untagged_unions to not allow union fields with drop
Union fields may now never have a type with attached destructor.
This for example allows unions to use arbitrary field types only by wrapping
them in ManuallyDrop (or similar).
The stable rule remains, that union fields must be Copy. We use the new
rule for the
untagged_union
feature.See RFC 2514, tracking issue #55149