diff options
| author | Daria Sukhonina <dariasukhonina@gmail.com> | 2024-04-27 11:59:50 +0300 |
|---|---|---|
| committer | Daria Sukhonina <dariasukhonina@gmail.com> | 2024-04-27 12:21:23 +0300 |
| commit | 255a1e9554286007ea5556f7123ceeeb3f9f6db1 (patch) | |
| tree | 5891d6e782e7415efe337e67281bbdf20be44ed7 | |
| parent | 9adafa7f8d72461426def828b5a8735a97eddc3f (diff) | |
| download | rust-255a1e9554286007ea5556f7123ceeeb3f9f6db1.tar.gz rust-255a1e9554286007ea5556f7123ceeeb3f9f6db1.zip | |
Relax `A: Clone` bound for `rc::Weak::into_raw_and_alloc`
| -rw-r--r-- | library/alloc/src/rc.rs | 11 |
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) } |
