about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-10-30 19:06:43 +0000
committerbors <bors@rust-lang.org>2015-10-30 19:06:43 +0000
commitcc8d398e28b6b1918ef85479c2d040dfd0fe582d (patch)
treeb509827a80ff356e37cf103d1af204eca809edfe /src/libcore
parent2aa9f7d3916dcff36a5b8b4978981c056ceb8398 (diff)
parente351595c61614c41be08f7508422d5f8a02d1a0e (diff)
downloadrust-cc8d398e28b6b1918ef85479c2d040dfd0fe582d.tar.gz
rust-cc8d398e28b6b1918ef85479c2d040dfd0fe582d.zip
Auto merge of #29475 - apasel422:drop-in, r=alexcrichton
This is a rebase of #27204.

r? @alexcrichton 
CC @Gankro 
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/intrinsics.rs21
-rw-r--r--src/libcore/ptr.rs2
2 files changed, 22 insertions, 1 deletions
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs
index 45b1c8a3599..429f4fbed28 100644
--- a/src/libcore/intrinsics.rs
+++ b/src/libcore/intrinsics.rs
@@ -195,7 +195,26 @@ extern "rust-intrinsic" {
 
     pub fn size_of_val<T: ?Sized>(_: &T) -> usize;
     pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize;
-    pub fn drop_in_place<T: ?Sized>(_: *mut T);
+
+    /// Executes the destructor (if any) of the pointed-to value.
+    ///
+    /// This has two use cases:
+    ///
+    /// * It is *required* to use `drop_in_place` to drop unsized types like
+    ///   trait objects, because they can't be read out onto the stack and
+    ///   dropped normally.
+    ///
+    /// * It is friendlier to the optimizer to do this over `ptr::read` when
+    ///   dropping manually allocated memory (e.g. when writing Box/Rc/Vec),
+    ///   as the compiler doesn't need to prove that it's sound to elide the
+    ///   copy.
+    ///
+    /// # Undefined Behavior
+    ///
+    /// This has all the same safety problems as `ptr::read` with respect to
+    /// invalid pointers, types, and double drops.
+    #[unstable(feature = "drop_in_place", reason = "just exposed, needs FCP", issue = "27908")]
+    pub fn drop_in_place<T: ?Sized>(to_drop: *mut T);
 
     /// Gets a static string slice containing the name of a type.
     pub fn type_name<T: ?Sized>() -> &'static str;
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index 52a888d797b..54cd3d0c867 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -40,6 +40,8 @@ pub use intrinsics::copy;
 #[stable(feature = "rust1", since = "1.0.0")]
 pub use intrinsics::write_bytes;
 
+pub use intrinsics::drop_in_place;
+
 /// Creates a null raw pointer.
 ///
 /// # Examples