@@ -46,29 +46,30 @@ annotate the dependencies somehow.
46
46
# Detailed design
47
47
[ design ] : #detailed-design
48
48
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 ` )
50
50
module. ` mem ` module is a most suitable place for such type, as the module already a place for
51
51
functions very similar in purpose: ` drop ` and ` forget ` .
52
52
53
53
``` rust
54
54
/// Inhibits compiler from automatically calling `T`’s destructor.
55
+ #[lang = " manually_drop" ]
55
56
#[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
+ }
58
61
59
62
impl <T > ManuallyDrop <T > {
60
63
/// Wraps a value to be manually dropped.
61
64
#[unstable(feature = " manually_drop" , reason = " recently added" , issue = " 0" )]
62
65
pub fn new (value : T ) -> ManuallyDrop <T > {
63
- ManuallyDrop { value : value }
66
+ ManuallyDrop { value }
64
67
}
65
68
66
69
/// Extracts the value from the ManuallyDrop container.
67
70
#[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
72
73
}
73
74
74
75
/// Manually drops the contained value.
@@ -92,11 +93,12 @@ impl<T> Deref for ManuallyDrop<T> {
92
93
impl <T > DerefMut for ManuallyDrop <T > {
93
94
// ...
94
95
}
95
-
96
- // Other common impls such as `Debug for T: Debug`.
97
96
```
98
97
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:
100
102
101
103
``` rust
102
104
struct FruitBox {
0 commit comments