Skip to content

Commit

Permalink
expose drop_in_place as ptr::drop_in_place
Browse files Browse the repository at this point in the history
  • Loading branch information
Gankra authored and apasel422 committed Oct 30, 2015
1 parent 914c4db commit e72c226
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/liballoc/lib.rs
Expand Up @@ -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))]

Expand Down
21 changes: 20 additions & 1 deletion src/libcore/intrinsics.rs
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/ptr.rs
Expand Up @@ -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
Expand Down

0 comments on commit e72c226

Please sign in to comment.