Skip to content
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

Stabilize ManuallyDrop::take #68066

Merged
merged 1 commit into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions src/libcore/mem/manually_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,28 @@ impl<T> ManuallyDrop<T> {
slot.value
}

/// Takes the contained value out.
/// Takes the value from the `ManuallyDrop<T>` container out.
///
/// This method is primarily intended for moving out values in drop.
/// Instead of using [`ManuallyDrop::drop`] to manually drop the value,
/// you can use this method to take the value and use it however desired.
/// `Drop` will be invoked on the returned value following normal end-of-scope rules.
///
/// If you have ownership of the container, you can use [`ManuallyDrop::into_inner`] instead.
/// Whenever possible, it is preferrable to use [`into_inner`][`ManuallyDrop::into_inner`]
/// instead, which prevents duplicating the content of the `ManuallyDrop<T>`.
///
/// # Safety
///
/// This function semantically moves out the contained value without preventing further usage.
/// It is up to the user of this method to ensure that this container is not used again.
/// This function semantically moves out the contained value without preventing further usage,
/// leaving the state of this container unchanged.
/// It is your responsibility to ensure that this `ManuallyDrop` is not used again.
///
/// [`ManuallyDrop::drop`]: #method.drop
/// [`ManuallyDrop::into_inner`]: #method.into_inner
#[must_use = "if you don't need the value, you can use `ManuallyDrop::drop` instead"]
#[unstable(feature = "manually_drop_take", issue = "55422")]
#[stable(feature = "manually_drop_take", since = "1.42.0")]
#[inline]
pub unsafe fn take(slot: &mut ManuallyDrop<T>) -> T {
ManuallyDrop::into_inner(ptr::read(slot))
ptr::read(&slot.value)
}
}

Expand Down
1 change: 0 additions & 1 deletion src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@
#![feature(link_args)]
#![feature(linkage)]
#![feature(log_syntax)]
#![feature(manually_drop_take)]
#![feature(maybe_uninit_ref)]
#![feature(maybe_uninit_slice)]
#![feature(needs_panic_runtime)]
Expand Down