From 255a1e9554286007ea5556f7123ceeeb3f9f6db1 Mon Sep 17 00:00:00 2001 From: Daria Sukhonina Date: Sat, 27 Apr 2024 11:59:50 +0300 Subject: [PATCH] Relax `A: Clone` bound for `rc::Weak::into_raw_and_alloc` --- library/alloc/src/rc.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index a320a244abd78..c245b42c3e880 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -3029,13 +3029,10 @@ impl Weak { /// [`as_ptr`]: Weak::as_ptr #[inline] #[unstable(feature = "allocator_api", issue = "32838")] - pub fn into_raw_and_alloc(self) -> (*const T, A) - where - A: Clone, - { - let result = self.as_ptr(); - let alloc = self.alloc.clone(); - mem::forget(self); + pub fn into_raw_and_alloc(self) -> (*const T, A) { + let rc = mem::ManuallyDrop::new(self); + let result = rc.as_ptr(); + let alloc = unsafe { ptr::read(&rc.alloc) }; (result, alloc) }