about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-11-22 13:43:05 +0100
committerRalf Jung <post@ralfj.de>2018-11-22 16:08:58 +0100
commitaf9b057156f610df3528a502c668cfed99ce8a1a (patch)
treed593b21ccab9ff40fb52bfe990efe2b781483785 /src/libcore
parent4bec59c93baa71d599a616fda9f1180febb08386 (diff)
downloadrust-af9b057156f610df3528a502c668cfed99ce8a1a.tar.gz
rust-af9b057156f610df3528a502c668cfed99ce8a1a.zip
drop glue takes in mutable references, it should reflect that in its type
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/ptr.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index e9cf11424ca..ba1028f76c1 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.