Skip to content

Commit 81e1ca5

Browse files
committed
Fix deref separation for async drop shim.
1 parent 54ed1bf commit 81e1ca5

1 file changed

Lines changed: 41 additions & 38 deletions

File tree

compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_middle::mir::{
99
use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeVisitableExt};
1010

1111
use super::*;
12+
use crate::deref_separator::deref_finder;
1213
use crate::patch::MirPatch;
1314

1415
pub(super) fn build_async_destructor_ctor_shim<'tcx>(
@@ -39,12 +40,12 @@ pub(super) fn build_async_destructor_ctor_shim<'tcx>(
3940
}
4041

4142
// build_drop_shim analog for async drop glue (for generated coroutine poll function)
43+
#[tracing::instrument(level = "trace", skip(tcx), ret)]
4244
pub(super) fn build_async_drop_shim<'tcx>(
4345
tcx: TyCtxt<'tcx>,
4446
def_id: DefId,
4547
ty: Ty<'tcx>,
4648
) -> Body<'tcx> {
47-
debug!("build_async_drop_shim(def_id={:?}, ty={:?})", def_id, ty);
4849
let ty::Coroutine(_, parent_args) = ty.kind() else {
4950
bug!();
5051
};
@@ -111,45 +112,47 @@ pub(super) fn build_async_drop_shim<'tcx>(
111112
parent_args.as_coroutine().resume_ty(),
112113
)));
113114
body.phase = MirPhase::Runtime(RuntimePhase::Initial);
114-
if !needs_async_drop || drop_ty.references_error() {
115-
// Returning noop body for types without `need async drop`
116-
// (or sync Drop in case of !`need async drop` && `need drop`).
117-
// And also for error types.
118-
return body;
119-
}
120-
121-
let dropee_ptr = Place::from(body.local_decls.push(LocalDecl::new(drop_ptr_ty, span)));
122-
let st_kind = StatementKind::Assign(Box::new((
123-
dropee_ptr,
124-
Rvalue::Use(Operand::Move(coroutine_layout_dropee), WithRetag::Yes),
125-
)));
126-
body.basic_blocks_mut()[START_BLOCK].statements.push(Statement::new(source_info, st_kind));
127115

128-
let dropline = body.basic_blocks.last_index();
129-
130-
let patch = {
131-
let mut elaborator = DropShimElaborator {
132-
body: &body,
133-
patch: MirPatch::new(&body),
134-
tcx,
135-
typing_env,
136-
produce_async_drops: true,
116+
// Returning noop body for types without `need async drop`
117+
// (or sync Drop in case of !`need async drop` && `need drop`).
118+
// And also for error types.
119+
if needs_async_drop && !drop_ty.references_error() {
120+
let dropee_ptr = Place::from(body.local_decls.push(LocalDecl::new(drop_ptr_ty, span)));
121+
let st_kind = StatementKind::Assign(Box::new((
122+
dropee_ptr,
123+
Rvalue::Use(Operand::Move(coroutine_layout_dropee), WithRetag::Yes),
124+
)));
125+
body.basic_blocks_mut()[START_BLOCK].statements.push(Statement::new(source_info, st_kind));
126+
127+
let dropline = body.basic_blocks.last_index();
128+
129+
let patch = {
130+
let mut elaborator = DropShimElaborator {
131+
body: &body,
132+
patch: MirPatch::new(&body),
133+
tcx,
134+
typing_env,
135+
produce_async_drops: true,
136+
};
137+
let dropee = tcx.mk_place_deref(dropee_ptr);
138+
let resume_block = elaborator.patch.resume_block();
139+
elaborate_drop(
140+
&mut elaborator,
141+
source_info,
142+
dropee,
143+
(),
144+
return_block,
145+
Unwind::To(resume_block),
146+
START_BLOCK,
147+
dropline,
148+
);
149+
elaborator.patch
137150
};
138-
let dropee = tcx.mk_place_deref(dropee_ptr);
139-
let resume_block = elaborator.patch.resume_block();
140-
elaborate_drop(
141-
&mut elaborator,
142-
source_info,
143-
dropee,
144-
(),
145-
return_block,
146-
Unwind::To(resume_block),
147-
START_BLOCK,
148-
dropline,
149-
);
150-
elaborator.patch
151-
};
152-
patch.apply(&mut body);
151+
patch.apply(&mut body);
152+
}
153+
154+
// We did not bother respectig deref separation, do it here.
155+
deref_finder(tcx, &mut body, false);
153156

154157
body
155158
}

0 commit comments

Comments
 (0)