Skip to content

Commit 27bfe2c

Browse files
committed
update ManuallyDrop RFC to reflect how the implementation now looks
1 parent 2d5218a commit 27bfe2c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

text/1860-manually-drop.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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`)
5050
module. `mem` module is a most suitable place for such type, as the module already a place for
5151
functions 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

5962
impl<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.
@@ -96,6 +97,9 @@ impl<T> DerefMut for ManuallyDrop<T> {
9697
// Other common impls such as `Debug for T: Debug`.
9798
```
9899

100+
The lang item will be treated specially by the compiler to not emit any drop
101+
glue for this type.
102+
99103
Let us apply this union to a somewhat expanded example from the motivation:
100104

101105
```rust

0 commit comments

Comments
 (0)