-
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
Remove destructor-related restrictions from unions #38934
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
@bors r+ |
📌 Commit efd1877 has been approved by |
@bors r- Travis failed, you need to maybe update compile-fail tests. |
We have a test, union-copy.rs, that tests that you can't impl Copy on a union containing noncopy types. Which is sort of the opposite of what this PR is trying to do. I thought the fact that unions can't be Copy was a bug; maybe it's intentional? Regardless, I feel that it should be possible to do this. |
Ah. #36016 (comment) mentions that there should be a test for #36016 (comment) is an opposition to that. cc @nikomatsakis @petrochenkov I'd really like to support copy being implemented on unions (even if |
Of course, the restriction is intentional, this change creates a hole in the current move/initialization semantics of unions and removes existing guarantees. |
I can remove the Got an explanation of the hole? |
Now union can be thought as an enum with unknown discriminant, so, for example, you have a guarantee that
Ha, this is much better. I believe the value returned by |
Split it into two commits. Are we okay with just landing the first one? |
@@ -235,6 +235,11 @@ impl<'a, 'tcx> ty::TyS<'tcx> { | |||
}) | |||
}); | |||
|
|||
if def.is_union() { | |||
// unions don't have destructors regardless of the child types |
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.
Could you add a test checking that needs_drop
still returns true
on unions that implement Drop
themselves?
I suspect the condition should be def.is_union() && !def.has_dtor()
instead of just def.is_union()
.
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.
The destructor is added below IIRC.
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.
Nah, that bit gets re-added below.
@Manishearth |
Done. |
@eddyb r? |
@bors r+ |
📌 Commit b9b0732 has been approved by |
⌛ Testing commit b9b0732 with merge 5b0ae4b... |
Woah. I feel that this whole discussion went by awfully fast. Can someone summarize the questions (and answers) on the tracking issue, please? (This seems to get at the philosophical debate about how best to think of unions that @petrochenkov and I were pursuing some time back.) |
💔 Test failed - status-travis |
@bors retry arm stalled |
FWIW, the current PR only changes the fact that unions containing dtors are |
Remove destructor-related restrictions from unions They don't have drop glue. This doesn't fix the rvalue promotion issues when trying to do things like `static FOO: NoDrop<Bar> = NoDrop {inner: Bar}`. I'm not sure if we should fix that.
☀️ Test successful - status-appveyor, status-travis |
OK, that seems pretty harmless. |
They don't have drop glue.
This doesn't fix the rvalue promotion issues when trying to do things like
static FOO: NoDrop<Bar> = NoDrop {inner: Bar}
. I'm not sure if we should fix that.