Skip to content

Commit 081e749

Browse files
committed
Insert assignment after Retag.
1 parent 1d7f4eb commit 081e749

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
@@ -514,8 +514,15 @@ fn make_coroutine_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body
514514
let source_info = SourceInfo::outermost(body.span);
515515
let pin_field = tcx.mk_place_field(SELF_ARG.into(), FieldIdx::ZERO, ref_coroutine_ty);
516516

517-
body.basic_blocks_mut()[START_BLOCK].statements.insert(
518-
0,
517+
let statements = &mut body.basic_blocks.as_mut_preserves_cfg()[START_BLOCK].statements;
518+
// Miri requires retags to be the very first thing in the body.
519+
// We insert this assignment just after.
520+
let insert_point = statements
521+
.iter()
522+
.position(|stmt| !matches!(stmt.kind, StatementKind::Retag(..)))
523+
.unwrap_or(statements.len());
524+
statements.insert(
525+
insert_point,
519526
Statement::new(
520527
source_info,
521528
StatementKind::Assign(Box::new((

0 commit comments

Comments
 (0)