Skip to content

Commit efbb3fa

Browse files
authored
Rollup merge of rust-lang#77547 - RalfJung:stable-union-drop, r=matthewjasper
stabilize union with 'ManuallyDrop' fields and 'impl Drop for Union' As [discussed by @SimonSapin and @withoutboats](rust-lang#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
2 parents e289eab + bd69c85 commit efbb3fa

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
#![feature(transparent_unions)]
132132
#![feature(unboxed_closures)]
133133
#![feature(unsized_locals)]
134-
#![feature(untagged_unions)]
134+
#![cfg_attr(bootstrap, feature(untagged_unions))]
135135
#![feature(unwind_attributes)]
136136
#![feature(variant_count)]
137137
#![feature(tbm_target_feature)]

core/src/ptr/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ pub(crate) struct FatPtr<T> {
229229
pub(crate) len: usize,
230230
}
231231

232+
// Manual impl needed to avoid `T: Clone` bound.
233+
impl<T> Clone for FatPtr<T> {
234+
fn clone(&self) -> Self {
235+
*self
236+
}
237+
}
238+
239+
// Manual impl needed to avoid `T: Copy` bound.
240+
impl<T> Copy for FatPtr<T> {}
241+
232242
/// Forms a raw slice from a pointer and a length.
233243
///
234244
/// The `len` argument is the number of **elements**, not the number of bytes.

std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@
319319
#![feature(unsafe_block_in_unsafe_fn)]
320320
#![feature(unsafe_cell_get_mut)]
321321
#![feature(unsafe_cell_raw_get)]
322-
#![feature(untagged_unions)]
322+
#![cfg_attr(bootstrap, feature(untagged_unions))]
323323
#![feature(unwind_attributes)]
324324
#![feature(vec_into_raw_parts)]
325325
#![feature(wake_trait)]

0 commit comments

Comments
 (0)