]> git.proxmox.com Git - rustc.git/blobdiff - library/alloc/src/boxed.rs
New upstream version 1.72.1+dfsg1
[rustc.git] / library / alloc / src / boxed.rs
index 1768687e8cd0263b0da8fd8cd401e4df0964d88c..8ef2bac9282cd4d417d78b622b317939b1d976a5 100644 (file)
@@ -1211,8 +1211,16 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Box<T, A> {
+    #[inline]
     fn drop(&mut self) {
-        // FIXME: Do nothing, drop is currently performed by compiler.
+        // the T in the Box is dropped by the compiler before the destructor is run
+
+        let ptr = self.0;
+
+        unsafe {
+            let layout = Layout::for_value_raw(ptr.as_ptr());
+            self.1.deallocate(From::from(ptr.cast()), layout)
+        }
     }
 }