Skip to content

Commit ed85b96

Browse files
committed
Insert assignment after Retag.
1 parent a15ef42 commit ed85b96

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,15 @@ fn make_coroutine_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body
546546
let source_info = SourceInfo::outermost(body.span);
547547
let pin_field = tcx.mk_place_field(SELF_ARG.into(), FieldIdx::ZERO, ref_coroutine_ty);
548548

549-
body.basic_blocks_mut()[START_BLOCK].statements.insert(
550-
0,
549+
let statements = &mut body.basic_blocks.as_mut_preserves_cfg()[START_BLOCK].statements;
550+
// Miri requires retags to be the very first thing in the body.
551+
// We insert this assignment just after.
552+
let insert_point = statements
553+
.iter()
554+
.position(|stmt| !matches!(stmt.kind, StatementKind::Retag(..)))
555+
.unwrap_or(statements.len());
556+
statements.insert(
557+
insert_point,
551558
Statement::new(
552559
source_info,
553560
StatementKind::Assign(Box::new((

0 commit comments

Comments
 (0)