Skip to content

Commit af9b057

Browse files
committed
drop glue takes in mutable references, it should reflect that in its type
1 parent 4bec59c commit af9b057

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/libcore/ptr.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,22 @@ pub use intrinsics::write_bytes;
189189
/// i.e., you do not usually have to worry about such issues unless you call `drop_in_place`
190190
/// manually.
191191
#[stable(feature = "drop_in_place", since = "1.8.0")]
192+
#[inline(always)]
193+
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
194+
real_drop_in_place(&mut *to_drop)
195+
}
196+
197+
// The real `drop_in_place` -- the one that gets called implicitly when variables go
198+
// out of scope -- should have a safe reference and not a raw pointer as argument
199+
// type. When we drop a local variable, we access it with a pointer that behaves
200+
// like a safe reference; transmuting that to a raw pointer does not mean we can
201+
// actually access it with raw pointers.
192202
#[lang = "drop_in_place"]
193203
#[allow(unconditional_recursion)]
194-
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
204+
unsafe fn real_drop_in_place<T: ?Sized>(to_drop: &mut T) {
195205
// Code here does not matter - this is replaced by the
196206
// real drop glue by the compiler.
197-
drop_in_place(to_drop);
207+
real_drop_in_place(to_drop)
198208
}
199209

200210
/// Creates a null raw pointer.

src/librustc_mir/interpret/terminator.rs

+3
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
196196
// that will take care to make it UB to leave the range, just
197197
// like for transmute).
198198
caller.value == callee.value,
199+
(layout::Abi::ScalarPair(ref caller1, ref caller2),
200+
layout::Abi::ScalarPair(ref callee1, ref callee2)) =>
201+
caller1.value == callee1.value && caller2.value == callee2.value,
199202
// Be conservative
200203
_ => false
201204
}

src/librustc_mir/shim.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,13 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
226226
// The first argument (index 0), but add 1 for the return value.
227227
let dropee_ptr = Place::Local(Local::new(1+0));
228228
if tcx.sess.opts.debugging_opts.mir_emit_retag {
229-
// We use raw ptr operations, better prepare the alias tracking for that
229+
// Function arguments should be retagged
230230
mir.basic_blocks_mut()[START_BLOCK].statements.insert(0, Statement {
231+
source_info,
232+
kind: StatementKind::Retag { fn_entry: true, place: dropee_ptr.clone() },
233+
});
234+
// We use raw ptr operations, better prepare the alias tracking for that
235+
mir.basic_blocks_mut()[START_BLOCK].statements.insert(1, Statement {
231236
source_info,
232237
kind: StatementKind::EscapeToRaw(Operand::Copy(dropee_ptr.clone())),
233238
})

0 commit comments

Comments
 (0)