Skip to content

update ManuallyDrop RFC to reflect how the implementation now looks #2510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions text/1860-manually-drop.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,30 @@ annotate the dependencies somehow.
# Detailed design
[design]: #detailed-design

This RFC proposes adding following `union` to the `core::mem` (and by extension the `std::mem`)
This RFC proposes adding the following `struct` as a new lang item to the `core::mem` (and by extension the `std::mem`)
module. `mem` module is a most suitable place for such type, as the module already a place for
functions very similar in purpose: `drop` and `forget`.

```rust
/// Inhibits compiler from automatically calling `T`’s destructor.
#[lang = "manually_drop"]
#[unstable(feature = "manually_drop", reason = "recently added", issue = "0")]
#[allow(unions_with_drop_fields)]
pub union ManuallyDrop<T>{ value: T }
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ManuallyDrop<T> {
value: T,
}

impl<T> ManuallyDrop<T> {
/// Wraps a value to be manually dropped.
#[unstable(feature = "manually_drop", reason = "recently added", issue = "0")]
pub fn new(value: T) -> ManuallyDrop<T> {
ManuallyDrop { value: value }
ManuallyDrop { value }
}

/// Extracts the value from the ManuallyDrop container.
#[unstable(feature = "manually_drop", reason = "recently added", issue = "0")]
pub fn into_inner(self) -> T {
unsafe {
self.value
}
pub fn into_inner(slot: ManuallyDrop<T>) -> T {
slot.value
}

/// Manually drops the contained value.
Expand All @@ -92,11 +93,12 @@ impl<T> Deref for ManuallyDrop<T> {
impl<T> DerefMut for ManuallyDrop<T> {
// ...
}

// Other common impls such as `Debug for T: Debug`.
```

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

Let us apply `ManuallyDrop` to a somewhat expanded example from the motivation:

```rust
struct FruitBox {
Expand Down