Skip to content

Commit 2508f17

Browse files
spastorinooli-obk
authored andcommitted
Promote Repeats to constants instead of statics
1 parent 1688719 commit 2508f17

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/librustc_mir/transform/promote_consts.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,10 +1002,25 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
10021002
StatementKind::Assign(box (_, Rvalue::Repeat(ref mut operand, _))) => {
10031003
let ty = operand.ty(local_decls, self.tcx);
10041004
let span = statement.source_info.span;
1005-
Rvalue::Use(mem::replace(
1006-
operand,
1007-
Operand::Copy(promoted_place(ty, span)),
1008-
))
1005+
1006+
promoted.span = span;
1007+
promoted.local_decls[RETURN_PLACE] =
1008+
LocalDecl::new_return_place(ty, span);
1009+
1010+
let promoted_operand = Operand::Constant(Box::new(Constant {
1011+
span,
1012+
user_ty: None,
1013+
literal: tcx.mk_const(ty::Const {
1014+
ty,
1015+
val: ty::ConstKind::Unevaluated(
1016+
def_id,
1017+
InternalSubsts::identity_for_item(tcx, def_id),
1018+
Some(promoted_id),
1019+
),
1020+
}),
1021+
}));
1022+
1023+
Rvalue::Use(mem::replace(operand, promoted_operand))
10091024
}
10101025
_ => bug!(),
10111026
}

0 commit comments

Comments
 (0)