diff options
| author | bors <bors@rust-lang.org> | 2017-03-20 15:58:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-03-20 15:58:10 +0000 |
| commit | 134c4a0f08a3d1f55ea8968fbe728fa935c71698 (patch) | |
| tree | f965ee88718069e91c5398a6084d33c64f4c03dc /src/libcore/ptr.rs | |
| parent | 244f893ed704a60841d4615445d540a21a8d7722 (diff) | |
| parent | 5dc8548050514b0781af7b21a4706552da18dd50 (diff) | |
| download | rust-134c4a0f08a3d1f55ea8968fbe728fa935c71698.tar.gz rust-134c4a0f08a3d1f55ea8968fbe728fa935c71698.zip | |
Auto merge of #39628 - arielb1:shimmir, r=eddyb
Translate shims using MIR This removes one large remaining part of old trans.
Diffstat (limited to 'src/libcore/ptr.rs')
| -rw-r--r-- | src/libcore/ptr.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 909e44df20a..f4eb1413850 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -37,9 +37,38 @@ pub use intrinsics::copy; #[stable(feature = "rust1", since = "1.0.0")] pub use intrinsics::write_bytes; +#[cfg(stage0)] #[stable(feature = "drop_in_place", since = "1.8.0")] pub use intrinsics::drop_in_place; +#[cfg(not(stage0))] +/// 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. +#[stable(feature = "drop_in_place", since = "1.8.0")] +#[lang="drop_in_place"] +#[inline] +#[allow(unconditional_recursion)] +pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) { + // Code here does not matter - this is replaced by the + // real drop glue by the compiler. + drop_in_place(to_drop); +} + /// Creates a null raw pointer. /// /// # Examples |
