Skip to content

Commit e43ff27

Browse files
committed
Auto merge of rust-lang#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.
2 parents bc31aa7 + b94c1ea commit e43ff27

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

alloc/src/rc.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -3029,13 +3029,10 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
30293029
/// [`as_ptr`]: Weak::as_ptr
30303030
#[inline]
30313031
#[unstable(feature = "allocator_api", issue = "32838")]
3032-
pub fn into_raw_and_alloc(self) -> (*const T, A)
3033-
where
3034-
A: Clone,
3035-
{
3036-
let result = self.as_ptr();
3037-
let alloc = self.alloc.clone();
3038-
mem::forget(self);
3032+
pub fn into_raw_and_alloc(self) -> (*const T, A) {
3033+
let rc = mem::ManuallyDrop::new(self);
3034+
let result = rc.as_ptr();
3035+
let alloc = unsafe { ptr::read(&rc.alloc) };
30393036
(result, alloc)
30403037
}
30413038

0 commit comments

Comments
 (0)