diff options
| author | Alexis Beingessner <a.beingessner@gmail.com> | 2015-07-21 14:11:50 -0700 |
|---|---|---|
| committer | Andrew Paseltiner <apaseltiner@gmail.com> | 2015-10-30 10:54:25 -0400 |
| commit | e72c226bed92bbbf9050044b9ebafa6b8deb0ea3 (patch) | |
| tree | eb3ba24351073b5ae435f3d3d00a67dc3516966b /src | |
| parent | 914c4dbc2a1037e63625b0bf846c6b550d0918c7 (diff) | |
| download | rust-e72c226bed92bbbf9050044b9ebafa6b8deb0ea3.tar.gz rust-e72c226bed92bbbf9050044b9ebafa6b8deb0ea3.zip | |
expose drop_in_place as ptr::drop_in_place
Diffstat (limited to 'src')
| -rw-r--r-- | src/liballoc/lib.rs | 2 | ||||
| -rw-r--r-- | src/libcore/intrinsics.rs | 21 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 2 |
3 files changed, 24 insertions, 1 deletions
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index c78ebdf4340..899e7de4ed5 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -103,6 +103,8 @@ #![feature(unsize)] #![feature(core_slice_ext)] #![feature(core_str_ext)] +#![feature(drop_in_place)] + #![cfg_attr(stage0, feature(alloc_system))] #![cfg_attr(not(stage0), feature(needs_allocator))] diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 45b1c8a3599..c14a07424a4 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 usecases: + /// + /// * 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 Behaviour + /// + /// 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 |
