about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-04-27 13:41:45 +0000
committerbors <bors@rust-lang.org>2024-04-27 13:41:45 +0000
commit61a1dbd751ab7f3c973be17d7ff3948ffda07c6e (patch)
tree651f1f53c4a7c527ea5265870e46b631ecef6be1
parent261823eee7021ae24e282e2ca28dbbd3d287b10f (diff)
parent255a1e9554286007ea5556f7123ceeeb3f9f6db1 (diff)
downloadrust-61a1dbd751ab7f3c973be17d7ff3948ffda07c6e.tar.gz
rust-61a1dbd751ab7f3c973be17d7ff3948ffda07c6e.zip
Auto merge of #124432 - zetanumbers:non_copy_into_raw_with_alloc, r=Nilstrieb
Relax `A: Clone` bound for `rc::Weak::into_raw_and_alloc`

Makes this method to behave the same way as [`Box::into_raw_with_allocator`](https://doc.rust-lang.org/1.77.2/alloc/boxed/struct.Box.html#method.into_raw_with_allocator) and [`Vec::into_raw_parts_with_alloc`](https://doc.rust-lang.org/1.77.2/alloc/vec/struct.Vec.html#method.into_raw_parts_with_alloc).

I have also noticed the inconsistent presence and naming, should probably be addressed in the future.
-rw-r--r--library/alloc/src/rc.rs11
1 files changed, 4 insertions, 7 deletions
diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs
index a320a244abd..c245b42c3e8 100644
--- a/library/alloc/src/rc.rs
+++ b/library/alloc/src/rc.rs
@@ -3029,13 +3029,10 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
     /// [`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)
     }