From 32fe47779b169cd8d637cfae3b130e004008e6f3 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 11 Dec 2019 00:09:49 -0300 Subject: [PATCH] Promote `Argument`s to constants instead of statics --- src/librustc_mir/transform/promote_consts.rs | 36 +++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index e160e922f4c44..a607383f77789 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -908,21 +908,6 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let promoted = &mut self.promoted; let promoted_id = Promoted::new(next_promoted_id); let tcx = self.tcx; - let mut promoted_place = |ty, span| { - promoted.span = span; - promoted.local_decls[RETURN_PLACE] = LocalDecl::new_return_place(ty, span); - Place { - base: PlaceBase::Static(box Static { - kind: StaticKind::Promoted( - promoted_id, - InternalSubsts::identity_for_item(tcx, def_id), - ), - ty, - def_id, - }), - projection: List::empty(), - } - }; let (blocks, local_decls) = self.source.basic_blocks_and_local_decls_mut(); match candidate { Candidate::Ref(loc) => { @@ -1031,8 +1016,25 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { TerminatorKind::Call { ref mut args, .. } => { let ty = args[index].ty(local_decls, self.tcx); let span = terminator.source_info.span; - let operand = Operand::Copy(promoted_place(ty, span)); - Rvalue::Use(mem::replace(&mut args[index], operand)) + + promoted.span = span; + promoted.local_decls[RETURN_PLACE] = + LocalDecl::new_return_place(ty, span); + + let promoted_operand = Operand::Constant(Box::new(Constant { + span, + user_ty: None, + literal: tcx.mk_const(ty::Const { + ty, + val: ty::ConstKind::Unevaluated( + def_id, + InternalSubsts::identity_for_item(tcx, def_id), + Some(promoted_id), + ), + }), + })); + + Rvalue::Use(mem::replace(&mut args[index], promoted_operand)) } // We expected a `TerminatorKind::Call` for which we'd like to promote an // argument. `qualify_consts` saw a `TerminatorKind::Call` here, but