diff options
| author | bors <bors@rust-lang.org> | 2018-12-01 07:06:17 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-12-01 07:06:17 +0000 |
| commit | d3ed34824c31f303b98855fee6fc9213dff1f295 (patch) | |
| tree | 25e7988d6f70275884d712e4b01fa3dead3c6e75 /src/libcore | |
| parent | aef4dbfaa7df8221cb4e99cbda1299b47b1c2aca (diff) | |
| parent | d9de72fcac7cfd90742a8fa8e4f6c0efd664ecde (diff) | |
| download | rust-d3ed34824c31f303b98855fee6fc9213dff1f295.tar.gz rust-d3ed34824c31f303b98855fee6fc9213dff1f295.zip | |
Auto merge of #56165 - RalfJung:drop-glue-type, r=eddyb,nikomatsakis
drop glue takes in mutable references, it should reflect that in its type When drop glue begins, it should retag, like all functions taking references do. But to do that, it needs to take the reference at a proper type: `&mut T`, not `*mut T`. Failing to retag can mean that the memory the reference points to remains frozen, and `EscapeToRaw` on a frozen location is a NOP, meaning later mutations cause a Stacked Borrows violation. Cc @nikomatsakis @Gankro because Stacked Borrows Cc @eddyb for the changes to miri argument passing (the intention is to allow passing `*mut [u8]` when `&mut [u8]` is expected and vice versa)
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/ptr.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 947b67e4e9a..d3a74ed2a68 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -189,12 +189,22 @@ pub use intrinsics::write_bytes; /// i.e., you do not usually have to worry about such issues unless you call `drop_in_place` /// manually. #[stable(feature = "drop_in_place", since = "1.8.0")] +#[inline(always)] +pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) { + real_drop_in_place(&mut *to_drop) +} + +// The real `drop_in_place` -- the one that gets called implicitly when variables go +// out of scope -- should have a safe reference and not a raw pointer as argument +// type. When we drop a local variable, we access it with a pointer that behaves +// like a safe reference; transmuting that to a raw pointer does not mean we can +// actually access it with raw pointers. #[lang = "drop_in_place"] #[allow(unconditional_recursion)] -pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) { +unsafe fn real_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); + real_drop_in_place(to_drop) } /// Creates a null raw pointer. |
