From 482ce025774c4a63849511ba6ebd24dfdfdd527b Mon Sep 17 00:00:00 2001 From: cad97 Date: Thu, 27 Jun 2019 21:06:35 -0400 Subject: [PATCH 1/2] Rename ManuallyDrop::take to read --- src/libcore/mem/manually_drop.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/libcore/mem/manually_drop.rs b/src/libcore/mem/manually_drop.rs index 3ad1223e331ec..f28b588e53916 100644 --- a/src/libcore/mem/manually_drop.rs +++ b/src/libcore/mem/manually_drop.rs @@ -85,27 +85,30 @@ impl ManuallyDrop { slot.value } - /// Takes the contained value out. + /// Reads the value from the `ManuallyDrop` container. The resulting `T` is subject + /// to the usual drop handling. /// /// 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. + /// you can use this method to read the value and use it however desired. /// - /// If you have ownership of the container, you can use [`ManuallyDrop::into_inner`] instead. + /// Whenever possible, it is preferable to use [`into_inner`][`ManuallyDrop::into_inner`] + /// instead, which prevents duplicating the content of the `ManuallyDrop`. /// /// # 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. + /// Like [`std::ptr::read`], this function semantically moves out the contained value + /// without preventing further usage, leaving the state of the container unchanged. + /// It is your responsibility to ensure that this `ManuallyDrop` is not reused after `read`. /// /// [`ManuallyDrop::drop`]: #method.drop /// [`ManuallyDrop::into_inner`]: #method.into_inner + /// [`std::ptr::read`]: ../ptr/fn.read.html #[must_use = "if you don't need the value, you can use `ManuallyDrop::drop` instead"] #[unstable(feature = "manually_drop_take", issue = "55422")] #[inline] - pub unsafe fn take(slot: &mut ManuallyDrop) -> T { - ManuallyDrop::into_inner(ptr::read(slot)) + pub unsafe fn read(slot: &mut ManuallyDrop) -> T { + ptr::read(&mut slot.value) } } From d304f55ed641ebd2a7c6352432627d263738eb11 Mon Sep 17 00:00:00 2001 From: cad97 Date: Fri, 28 Jun 2019 12:45:18 -0400 Subject: [PATCH 2/2] Remove unnecessary &mut in ManuallyDrop::read --- src/libcore/mem/manually_drop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/mem/manually_drop.rs b/src/libcore/mem/manually_drop.rs index f28b588e53916..de1a73d126333 100644 --- a/src/libcore/mem/manually_drop.rs +++ b/src/libcore/mem/manually_drop.rs @@ -108,7 +108,7 @@ impl ManuallyDrop { #[unstable(feature = "manually_drop_take", issue = "55422")] #[inline] pub unsafe fn read(slot: &mut ManuallyDrop) -> T { - ptr::read(&mut slot.value) + ptr::read(&slot.value) } }