]> git.lizzy.rs Git - rust.git/blobdiff - library/alloc/src/vec/in_place_drop.rs
Auto merge of #104990 - matthiaskrgr:rollup-oskk8v3, r=matthiaskrgr
[rust.git] / library / alloc / src / vec / in_place_drop.rs
index 1b1ef9130face38781d9b97912f5f314bfdd7bdf..25ca33c6a7bf0576921f249fcf48782663bf6c87 100644 (file)
@@ -22,3 +22,18 @@ fn drop(&mut self) {
         }
     }
 }
+
+// A helper struct for in-place collection that drops the destination allocation and elements,
+// to avoid leaking them if some other destructor panics.
+pub(super) struct InPlaceDstBufDrop<T> {
+    pub(super) ptr: *mut T,
+    pub(super) len: usize,
+    pub(super) cap: usize,
+}
+
+impl<T> Drop for InPlaceDstBufDrop<T> {
+    #[inline]
+    fn drop(&mut self) {
+        unsafe { super::Vec::from_raw_parts(self.ptr, self.len, self.cap) };
+    }
+}