@@ -46,29 +46,30 @@ annotate the dependencies somehow.
4646# Detailed design
4747[ design ] : #detailed-design
4848
49- This RFC proposes adding following ` union ` to the ` core::mem ` (and by extension the ` std::mem ` )
49+ This RFC proposes adding the following ` struct ` as a new lang item to the ` core::mem ` (and by extension the ` std::mem ` )
5050module. ` mem ` module is a most suitable place for such type, as the module already a place for
5151functions very similar in purpose: ` drop ` and ` forget ` .
5252
5353``` rust
5454/// Inhibits compiler from automatically calling `T`’s destructor.
55+ #[lang = " manually_drop" ]
5556#[unstable(feature = " manually_drop" , reason = " recently added" , issue = " 0" )]
56- #[allow(unions_with_drop_fields)]
57- pub union ManuallyDrop <T >{ value : T }
57+ #[derive(Copy , Clone , Debug , Default , PartialEq , Eq , PartialOrd , Ord , Hash )]
58+ pub struct ManuallyDrop <T > {
59+ value : T ,
60+ }
5861
5962impl <T > ManuallyDrop <T > {
6063 /// Wraps a value to be manually dropped.
6164 #[unstable(feature = " manually_drop" , reason = " recently added" , issue = " 0" )]
6265 pub fn new (value : T ) -> ManuallyDrop <T > {
63- ManuallyDrop { value : value }
66+ ManuallyDrop { value }
6467 }
6568
6669 /// Extracts the value from the ManuallyDrop container.
6770 #[unstable(feature = " manually_drop" , reason = " recently added" , issue = " 0" )]
68- pub fn into_inner (self ) -> T {
69- unsafe {
70- self . value
71- }
71+ pub fn into_inner (slot : ManuallyDrop <T >) -> T {
72+ slot . value
7273 }
7374
7475 /// Manually drops the contained value.
@@ -92,11 +93,12 @@ impl<T> Deref for ManuallyDrop<T> {
9293impl <T > DerefMut for ManuallyDrop <T > {
9394 // ...
9495}
95-
96- // Other common impls such as `Debug for T: Debug`.
9796```
9897
99- Let us apply this union to a somewhat expanded example from the motivation:
98+ The lang item will be treated specially by the compiler to not emit any drop
99+ glue for this type.
100+
101+ Let us apply ` ManuallyDrop ` to a somewhat expanded example from the motivation:
100102
101103``` rust
102104struct FruitBox {
0 commit comments