Skip to content

Commit 4b7ff2f

Browse files
authored
Merge pull request #2510 from RalfJung/manually-drop
update ManuallyDrop RFC to reflect how the implementation now looks
2 parents 2d5218a + 1e08ea2 commit 4b7ff2f

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

text/1860-manually-drop.md

+13-11
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.
@@ -92,11 +93,12 @@ impl<T> Deref for ManuallyDrop<T> {
9293
impl<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
102104
struct FruitBox {

0 commit comments

Comments
 (0)