Uh oh!
There was an error while loading. Please reload this page.
Remove destructor-related restrictions from unions - #38934
Conversation
rust-highfive
commented
Jan 8, 2017
(rust_highfive has picked a reviewer for you, use r? to override) |
eddyb
commented
Jan 8, 2017
@bors r+ |
bors
commented
Jan 8, 2017
📌 Commit efd1877 has been approved by |
eddyb
commented
Jan 9, 2017
@bors r- Travis failed, you need to maybe update compile-fail tests. |
Manishearth
commented
Jan 9, 2017
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. |
Manishearth
commented
Jan 9, 2017
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 |
petrochenkov
commented
Jan 9, 2017
Of course, the restriction is intentional, this change creates a hole in the current move/initialization semantics of unions and removes existing guarantees. |
Manishearth
commented
Jan 9, 2017
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 |
Manishearth
commented
Jan 9, 2017
Split it into two commits. Are we okay with just landing the first one? |
There was a problem hiding this comment.
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.
The destructor is added below IIRC.
There was a problem hiding this comment.
Nah, that bit gets re-added below.
petrochenkov
commented
Jan 9, 2017
@Manishearth |
Manishearth
commented
Jan 9, 2017
Done. |
Manishearth
commented
Jan 9, 2017
@eddyb r? |
eddyb
commented
Jan 9, 2017
@bors r+ |
bors
commented
Jan 9, 2017
📌 Commit b9b0732 has been approved by |
bors
commented
Jan 9, 2017
⌛ Testing commit b9b0732 with merge 5b0ae4b... |
nikomatsakis
commented
Jan 9, 2017
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.) |
bors
commented
Jan 9, 2017
💔 Test failed - status-travis |
@bors retry arm stalled |
Manishearth
commented
Jan 9, 2017
FWIW, the current PR only changes the fact that unions containing dtors are |
bors
commented
Jan 10, 2017
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.bors
commented
Jan 10, 2017
☀️ Test successful - status-appveyor, status-travis |
nikomatsakis
commented
Jan 10, 2017
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.