Skip to content

Commit 0447b50

Browse files
committed
fix array drop glue: properly turn raw ptr into reference
1 parent bf1e461 commit 0447b50

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/librustc_mir/util/elaborate_drops.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
562562
/// if can_go then succ else drop-block
563563
/// drop-block:
564564
/// if ptr_based {
565-
/// ptr = cur
565+
/// ptr = &mut *cur
566566
/// cur = cur.offset(1)
567567
/// } else {
568568
/// ptr = &mut P[cur]
@@ -591,7 +591,14 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
591591

592592
let one = self.constant_usize(1);
593593
let (ptr_next, cur_next) = if ptr_based {
594-
(Rvalue::Use(copy(&Place::Local(cur))),
594+
(Rvalue::Ref(
595+
tcx.types.re_erased,
596+
BorrowKind::Mut { allow_two_phase_borrow: false },
597+
Place::Projection(Box::new(Projection {
598+
base: Place::Local(cur),
599+
elem: ProjectionElem::Deref,
600+
}))
601+
),
595602
Rvalue::BinaryOp(BinOp::Offset, copy(&Place::Local(cur)), one))
596603
} else {
597604
(Rvalue::Ref(
@@ -736,7 +743,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
736743
if ptr_based {
737744
let tmp_ty = tcx.mk_mut_ptr(self.place_ty(self.place));
738745
let tmp = Place::Local(self.new_temp(tmp_ty));
739-
// tmp = &P;
746+
// tmp = &mut P;
740747
// cur = tmp as *mut T;
741748
// end = Offset(cur, len);
742749
drop_block_stmts.push(self.assign(&tmp, Rvalue::Ref(

0 commit comments

Comments
 (0)