Skip to content

Commit cefe65b

Browse files
committed
Promote Arguments to constants instead of statics
1 parent 4b9a90d commit cefe65b

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/librustc_mir/transform/promote_consts.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -950,22 +950,6 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
950950
let promoted = &mut self.promoted;
951951
let promoted_id = Promoted::new(next_promoted_id);
952952
let tcx = self.tcx;
953-
let mut promoted_place = |ty, span| {
954-
promoted.span = span;
955-
promoted.local_decls[RETURN_PLACE] = LocalDecl::new_return_place(ty, span);
956-
Place {
957-
base: PlaceBase::Static(box Static {
958-
kind:
959-
StaticKind::Promoted(
960-
promoted_id,
961-
InternalSubsts::identity_for_item(tcx, def_id),
962-
),
963-
ty,
964-
def_id,
965-
}),
966-
projection: List::empty(),
967-
}
968-
};
969953
let (blocks, local_decls) = self.source.basic_blocks_and_local_decls_mut();
970954
match candidate {
971955
Candidate::Ref(loc) => {
@@ -1074,8 +1058,25 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
10741058
TerminatorKind::Call { ref mut args, .. } => {
10751059
let ty = args[index].ty(local_decls, self.tcx);
10761060
let span = terminator.source_info.span;
1077-
let operand = Operand::Copy(promoted_place(ty, span));
1078-
Rvalue::Use(mem::replace(&mut args[index], operand))
1061+
1062+
promoted.span = span;
1063+
promoted.local_decls[RETURN_PLACE] =
1064+
LocalDecl::new_return_place(ty, span);
1065+
1066+
let promoted_operand = Operand::Constant(Box::new(Constant {
1067+
span,
1068+
user_ty: None,
1069+
literal: tcx.mk_const(ty::Const {
1070+
ty,
1071+
val: ty::ConstKind::Unevaluated(
1072+
def_id,
1073+
InternalSubsts::identity_for_item(tcx, def_id),
1074+
Some(promoted_id),
1075+
),
1076+
}),
1077+
}));
1078+
1079+
Rvalue::Use(mem::replace(&mut args[index], promoted_operand))
10791080
}
10801081
// We expected a `TerminatorKind::Call` for which we'd like to promote an
10811082
// argument. `qualify_consts` saw a `TerminatorKind::Call` here, but
@@ -1085,7 +1086,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
10851086
// providing a value whose computation contains another call to a function
10861087
// requiring a constant argument.
10871088
TerminatorKind::Goto { .. } => return None,
1088-
_ => bug!()
1089+
_ => bug!(),
10891090
}
10901091
}
10911092
}

0 commit comments

Comments
 (0)