Skip to content

Commit 4842194

Browse files
committed
remove retag from drop shim
1 parent 2c330e0 commit 4842194

2 files changed

Lines changed: 10 additions & 28 deletions

File tree

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -298,35 +298,17 @@ fn local_decls_for_sig<'tcx>(
298298
fn dropee_emit_retag<'tcx>(
299299
tcx: TyCtxt<'tcx>,
300300
body: &mut Body<'tcx>,
301-
mut dropee_ptr: Place<'tcx>,
301+
dropee_ptr: Place<'tcx>,
302302
span: Span,
303-
) -> Place<'tcx> {
303+
) {
304304
if tcx.sess.opts.unstable_opts.mir_emit_retag {
305305
let source_info = SourceInfo::outermost(span);
306-
// We want to treat the function argument as if it was passed by `&mut`. As such, we
307-
// generate
308-
// ```
309-
// temp = &mut *arg;
310-
// Retag(temp, FnEntry)
311-
// ```
312-
// It's important that we do this first, before anything that depends on `dropee_ptr`
313-
// has been put into the body.
314-
let reborrow = Rvalue::Ref(
315-
tcx.lifetimes.re_erased,
316-
BorrowKind::Mut { kind: MutBorrowKind::Default },
317-
tcx.mk_place_deref(dropee_ptr),
318-
);
319-
let ref_ty = reborrow.ty(body.local_decls(), tcx);
320-
dropee_ptr = body.local_decls.push(LocalDecl::new(ref_ty, span)).into();
321-
let new_statements = [
322-
StatementKind::Assign(Box::new((dropee_ptr, reborrow))),
323-
StatementKind::Retag(RetagKind::FnEntry, Box::new(dropee_ptr)),
324-
];
325-
for s in new_statements {
326-
body.basic_blocks_mut()[START_BLOCK].statements.push(Statement::new(source_info, s));
327-
}
306+
let new_statement = StatementKind::Retag(RetagKind::FnEntry, Box::new(dropee_ptr));
307+
308+
body.basic_blocks_mut()[START_BLOCK]
309+
.statements
310+
.push(Statement::new(source_info, new_statement));
328311
}
329-
dropee_ptr
330312
}
331313

332314
fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>) -> Body<'tcx> {
@@ -359,7 +341,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
359341

360342
// The first argument (index 0), but add 1 for the return value.
361343
let dropee_ptr = Place::from(Local::new(1 + 0));
362-
let dropee_ptr = dropee_emit_retag(tcx, &mut body, dropee_ptr, span);
344+
dropee_emit_retag(tcx, &mut body, dropee_ptr, span);
363345

364346
if ty.is_some() {
365347
let patch = {

compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ pub(super) fn build_async_drop_shim<'tcx>(
124124
return body;
125125
}
126126

127-
let mut dropee_ptr = Place::from(body.local_decls.push(LocalDecl::new(drop_ptr_ty, span)));
127+
let dropee_ptr = Place::from(body.local_decls.push(LocalDecl::new(drop_ptr_ty, span)));
128128
let st_kind = StatementKind::Assign(Box::new((
129129
dropee_ptr,
130130
Rvalue::Use(Operand::Move(coroutine_layout_dropee)),
131131
)));
132132
body.basic_blocks_mut()[START_BLOCK].statements.push(Statement::new(source_info, st_kind));
133-
dropee_ptr = dropee_emit_retag(tcx, &mut body, dropee_ptr, span);
133+
dropee_emit_retag(tcx, &mut body, dropee_ptr, span);
134134

135135
let dropline = body.basic_blocks.last_index();
136136

0 commit comments

Comments
 (0)