Skip to content

Commit b5a3341

Browse files
committed
Auto merge of #68066 - CAD97:stabilize-manuallydrop-take, r=Amanieu,Mark-Simulacrum
Stabilize ManuallyDrop::take Tracking issue: closes #55422 FCP merge: #55422 (comment) Reclaims the doc improvements from closed #62198. ----- Stable version is a simple change if necessary. Proposal: [relnotes] (this changes how to best take advantage of `ManuallyDrop`, esp. wrt. `Drop::drop` and finalize-by-value members)
2 parents 66b0c97 + 4e98966 commit b5a3341

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/libcore/mem/manually_drop.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,28 @@ impl<T> ManuallyDrop<T> {
8787
slot.value
8888
}
8989

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

src/libstd/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@
275275
#![feature(link_args)]
276276
#![feature(linkage)]
277277
#![feature(log_syntax)]
278-
#![feature(manually_drop_take)]
279278
#![feature(maybe_uninit_ref)]
280279
#![feature(maybe_uninit_slice)]
281280
#![feature(needs_panic_runtime)]

0 commit comments

Comments
 (0)