Skip to content

Commit 536f126

Browse files
committed
Insert assignment after Retag.
1 parent 76324c7 commit 536f126

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

554-
body.basic_blocks_mut()[START_BLOCK].statements.insert(
555-
0,
554+
let statements = &mut body.basic_blocks.as_mut_preserves_cfg()[START_BLOCK].statements;
555+
// Miri requires retags to be the very first thing in the body.
556+
// We insert this assignment just after.
557+
let insert_point = statements
558+
.iter()
559+
.position(|stmt| !matches!(stmt.kind, StatementKind::Retag(..)))
560+
.unwrap_or(statements.len());
561+
statements.insert(
562+
insert_point,
556563
Statement::new(
557564
source_info,
558565
StatementKind::Assign(Box::new((

0 commit comments

Comments
 (0)