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 | |
| parent | 244f893ed704a60841d4615445d540a21a8d7722 (diff) | |
| parent | 5dc8548050514b0781af7b21a4706552da18dd50 (diff) | |
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')
| -rw-r--r-- | src/libcore/intrinsics.rs | 8 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 29 |
2 files changed, 36 insertions, 1 deletions
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index f8d067e9696..1ae8b6bb451 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -46,8 +46,13 @@ issue = "0")] #![allow(missing_docs)] -extern "rust-intrinsic" { +#[cfg(not(stage0))] +#[stable(feature = "drop_in_place", since = "1.8.0")] +#[rustc_deprecated(reason = "no longer an intrinsic - use `ptr::drop_in_place` directly", + since = "1.18.0")] +pub use ptr::drop_in_place; +extern "rust-intrinsic" { // NB: These intrinsics take raw pointers because they mutate aliased // memory, which is not valid for either `&` or `&mut`. @@ -622,6 +627,7 @@ extern "rust-intrinsic" { pub fn size_of_val<T: ?Sized>(_: &T) -> usize; pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize; + #[cfg(stage0)] /// Executes the destructor (if any) of the pointed-to value. /// /// This has two use cases: 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 |
