@@ -1872,15 +1872,17 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> { |
|
|
1872 |
1872 |
// Non-inlined part of `drop`. |
1873 |
1873 |
#[inline(never)] |
1874 |
1874 |
unsafe fn drop_slow(&mut self) { |
|
1875 |
+// Drop the weak ref collectively held by all strong references when this |
|
1876 |
+// variable goes out of scope. This ensures that the memory is deallocated |
|
1877 |
+// even if the destructor of `T` panics. |
|
1878 |
+// Take a reference to `self.alloc` instead of cloning because 1. it'll last long |
|
1879 |
+// enough, and 2. you should be able to drop `Arc`s with unclonable allocators |
|
1880 |
+let _weak = Weak { ptr: self.ptr, alloc: &self.alloc }; |
|
1881 |
+ |
1875 |
1882 |
// Destroy the data at this time, even though we must not free the box |
1876 |
1883 |
// allocation itself (there might still be weak pointers lying around). |
1877 |
|
-unsafe { ptr::drop_in_place(Self::get_mut_unchecked(self)) }; |
1878 |
|
- |
1879 |
|
-// Drop the weak ref collectively held by all strong references |
1880 |
|
-// Take a reference to `self.alloc` instead of cloning because 1. it'll |
1881 |
|
-// last long enough, and 2. you should be able to drop `Arc`s with |
1882 |
|
-// unclonable allocators |
1883 |
|
-drop(Weak { ptr: self.ptr, alloc: &self.alloc }); |
|
1884 |
+// We cannot use `get_mut_unchecked` here, because `self.alloc` is borrowed. |
|
1885 |
+unsafe { ptr::drop_in_place(&mut (*self.ptr.as_ptr()).data) }; |
1884 |
1886 |
} |
1885 |
1887 |
|
1886 |
1888 |
/// Returns `true` if the two `Arc`s point to the same allocation in a vein similar to |