From 1141136b90663cf9d5ee6325b2f9e47f02e70746 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 16 Jul 2019 09:17:35 +0200 Subject: Use ManuallyDrop instead of mem::forget Per https://github.com/rust-lang/rust/pull/62451#discussion_r303197278 --- src/liballoc/rc.rs | 8 ++------ src/liballoc/sync.rs | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 70911790be2..c76c4b50c64 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -495,10 +495,8 @@ impl Rc> { #[unstable(feature = "new_uninit", issue = "0")] #[inline] pub unsafe fn assume_init(self) -> Rc { - let ptr = self.ptr.cast(); - mem::forget(self); Rc { - ptr, + ptr: mem::ManuallyDrop::new(self).ptr.cast(), phantom: PhantomData, } } @@ -541,10 +539,8 @@ impl Rc<[mem::MaybeUninit]> { #[unstable(feature = "new_uninit", issue = "0")] #[inline] pub unsafe fn assume_init(self) -> Rc<[T]> { - let ptr = NonNull::new_unchecked(self.ptr.as_ptr() as _); - mem::forget(self); Rc { - ptr, + ptr: NonNull::new_unchecked(mem::ManuallyDrop::new(self).ptr.as_ptr() as _), phantom: PhantomData, } } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 901d2d831d1..bc3acd27e8b 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -479,10 +479,8 @@ impl Arc> { #[unstable(feature = "new_uninit", issue = "0")] #[inline] pub unsafe fn assume_init(self) -> Arc { - let ptr = self.ptr.cast(); - mem::forget(self); Arc { - ptr, + ptr: mem::ManuallyDrop::new(self).ptr.cast(), phantom: PhantomData, } } @@ -525,10 +523,8 @@ impl Arc<[mem::MaybeUninit]> { #[unstable(feature = "new_uninit", issue = "0")] #[inline] pub unsafe fn assume_init(self) -> Arc<[T]> { - let ptr = NonNull::new_unchecked(self.ptr.as_ptr() as _); - mem::forget(self); Arc { - ptr, + ptr: NonNull::new_unchecked(mem::ManuallyDrop::new(self).ptr.as_ptr() as _), phantom: PhantomData, } } -- cgit 1.4.1-3-g733a5