Skip to content

Commit 4b9a90d

Browse files
committed
Promote Repeats to constants instead of statics
1 parent 87e6a37 commit 4b9a90d

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/librustc_mir/transform/promote_consts.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,17 +1042,32 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
10421042
Candidate::Repeat(loc) => {
10431043
let ref mut statement = blocks[loc.block].statements[loc.statement_index];
10441044
match statement.kind {
1045-
StatementKind::Assign(box(_, Rvalue::Repeat(ref mut operand, _))) => {
1045+
StatementKind::Assign(box (_, Rvalue::Repeat(ref mut operand, _))) => {
10461046
let ty = operand.ty(local_decls, self.tcx);
10471047
let span = statement.source_info.span;
1048-
Rvalue::Use(mem::replace(
1049-
operand,
1050-
Operand::Copy(promoted_place(ty, span))
1051-
))
1048+
1049+
promoted.span = span;
1050+
promoted.local_decls[RETURN_PLACE] =
1051+
LocalDecl::new_return_place(ty, span);
1052+
1053+
let promoted_operand = Operand::Constant(Box::new(Constant {
1054+
span,
1055+
user_ty: None,
1056+
literal: tcx.mk_const(ty::Const {
1057+
ty,
1058+
val: ty::ConstKind::Unevaluated(
1059+
def_id,
1060+
InternalSubsts::identity_for_item(tcx, def_id),
1061+
Some(promoted_id),
1062+
),
1063+
}),
1064+
}));
1065+
1066+
Rvalue::Use(mem::replace(operand, promoted_operand))
10521067
}
1053-
_ => bug!()
1068+
_ => bug!(),
10541069
}
1055-
},
1070+
}
10561071
Candidate::Argument { bb, index } => {
10571072
let terminator = blocks[bb].terminator_mut();
10581073
match terminator.kind {

0 commit comments

Comments
 (0)