-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #77547 - RalfJung:stable-union-drop, r=matthewjasper
stabilize union with 'ManuallyDrop' fields and 'impl Drop for Union' As [discussed by @SimonSapin and @withoutboats](#55149 (comment)), this PR proposes to stabilize parts of the `untagged_union` feature gate: * It will be possible to have a union with field type `ManuallyDrop<T>` for any `T`. * While at it I propose we also stabilize `impl Drop for Union`; to my knowledge, there are no open concerns around this feature. In the RFC discussion, we also talked about allowing `&mut T` as another non-`Copy` non-dropping type, but that felt to me like an overly specific exception so I figured we'd wait if there is actually any use for such a special case. Some things remain unstable and still require the `untagged_union` feature gate: * Union with fields that do not drop, are not `Copy`, and are not `ManuallyDrop<_>`. The reason to not stabilize this is to avoid semver concerns around libraries adding `Drop` implementations later. (This is already not fully semver compatible as, to my knowledge, the borrow checker will exploit the non-dropping nature of any type, but it seems prudent to avoid further increasing the amount of trouble adding an `impl Drop` can cause.) Due to this, quite a few tests still need the `untagged_union` feature, but I think the ones where I could remove the feature flag provide good test coverage for the stable part. Cc @rust-lang/lang
- Loading branch information
Showing
33 changed files
with
109 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#![feature(untagged_unions)] | ||
|
||
use std::cell::Cell; | ||
use std::ops::Deref; | ||
use std::mem::ManuallyDrop; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 9 additions & 33 deletions
42
src/test/ui/feature-gates/feature-gate-untagged_unions.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,37 @@ | ||
error[E0658]: unions with non-`Copy` fields are unstable | ||
--> $DIR/feature-gate-untagged_unions.rs:9:1 | ||
error[E0658]: unions with non-`Copy` fields other than `ManuallyDrop<T>` are unstable | ||
--> $DIR/feature-gate-untagged_unions.rs:20:5 | ||
| | ||
LL | / union U3 { | ||
LL | | a: String, | ||
LL | | } | ||
| |_^ | ||
| | ||
= note: see issue #55149 <https://github.com/rust-lang/rust/issues/55149> for more information | ||
= help: add `#![feature(untagged_unions)]` to the crate attributes to enable | ||
|
||
error[E0658]: unions with non-`Copy` fields are unstable | ||
--> $DIR/feature-gate-untagged_unions.rs:13:1 | ||
| | ||
LL | / union U4<T> { | ||
LL | | a: T, | ||
LL | | } | ||
| |_^ | ||
| | ||
= note: see issue #55149 <https://github.com/rust-lang/rust/issues/55149> for more information | ||
= help: add `#![feature(untagged_unions)]` to the crate attributes to enable | ||
|
||
error[E0658]: unions with `Drop` implementations are unstable | ||
--> $DIR/feature-gate-untagged_unions.rs:17:1 | ||
| | ||
LL | / union U5 { | ||
LL | | a: u8, | ||
LL | | } | ||
| |_^ | ||
LL | a: std::cell::RefCell<i32>, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #55149 <https://github.com/rust-lang/rust/issues/55149> for more information | ||
= help: add `#![feature(untagged_unions)]` to the crate attributes to enable | ||
|
||
error[E0740]: unions may not contain fields that need dropping | ||
--> $DIR/feature-gate-untagged_unions.rs:10:5 | ||
--> $DIR/feature-gate-untagged_unions.rs:16:5 | ||
| | ||
LL | a: String, | ||
| ^^^^^^^^^ | ||
| | ||
note: `std::mem::ManuallyDrop` can be used to wrap the type | ||
--> $DIR/feature-gate-untagged_unions.rs:10:5 | ||
--> $DIR/feature-gate-untagged_unions.rs:16:5 | ||
| | ||
LL | a: String, | ||
| ^^^^^^^^^ | ||
|
||
error[E0740]: unions may not contain fields that need dropping | ||
--> $DIR/feature-gate-untagged_unions.rs:14:5 | ||
--> $DIR/feature-gate-untagged_unions.rs:24:5 | ||
| | ||
LL | a: T, | ||
| ^^^^ | ||
| | ||
note: `std::mem::ManuallyDrop` can be used to wrap the type | ||
--> $DIR/feature-gate-untagged_unions.rs:14:5 | ||
--> $DIR/feature-gate-untagged_unions.rs:24:5 | ||
| | ||
LL | a: T, | ||
| ^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0658, E0740. | ||
For more information about an error, try `rustc --explain E0658`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.