Skip to content

Commit 32fe477

Browse files
spastorinooli-obk
authored andcommitted
Promote Arguments to constants instead of statics
1 parent 2508f17 commit 32fe477

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/librustc_mir/transform/promote_consts.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -908,21 +908,6 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
908908
let promoted = &mut self.promoted;
909909
let promoted_id = Promoted::new(next_promoted_id);
910910
let tcx = self.tcx;
911-
let mut promoted_place = |ty, span| {
912-
promoted.span = span;
913-
promoted.local_decls[RETURN_PLACE] = LocalDecl::new_return_place(ty, span);
914-
Place {
915-
base: PlaceBase::Static(box Static {
916-
kind: StaticKind::Promoted(
917-
promoted_id,
918-
InternalSubsts::identity_for_item(tcx, def_id),
919-
),
920-
ty,
921-
def_id,
922-
}),
923-
projection: List::empty(),
924-
}
925-
};
926911
let (blocks, local_decls) = self.source.basic_blocks_and_local_decls_mut();
927912
match candidate {
928913
Candidate::Ref(loc) => {
@@ -1031,8 +1016,25 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
10311016
TerminatorKind::Call { ref mut args, .. } => {
10321017
let ty = args[index].ty(local_decls, self.tcx);
10331018
let span = terminator.source_info.span;
1034-
let operand = Operand::Copy(promoted_place(ty, span));
1035-
Rvalue::Use(mem::replace(&mut args[index], operand))
1019+
1020+
promoted.span = span;
1021+
promoted.local_decls[RETURN_PLACE] =
1022+
LocalDecl::new_return_place(ty, span);
1023+
1024+
let promoted_operand = Operand::Constant(Box::new(Constant {
1025+
span,
1026+
user_ty: None,
1027+
literal: tcx.mk_const(ty::Const {
1028+
ty,
1029+
val: ty::ConstKind::Unevaluated(
1030+
def_id,
1031+
InternalSubsts::identity_for_item(tcx, def_id),
1032+
Some(promoted_id),
1033+
),
1034+
}),
1035+
}));
1036+
1037+
Rvalue::Use(mem::replace(&mut args[index], promoted_operand))
10361038
}
10371039
// We expected a `TerminatorKind::Call` for which we'd like to promote an
10381040
// argument. `qualify_consts` saw a `TerminatorKind::Call` here, but

0 commit comments

Comments
 (0)