@@ -950,22 +950,6 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
950
950
let promoted = & mut self . promoted ;
951
951
let promoted_id = Promoted :: new ( next_promoted_id) ;
952
952
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
- } ;
969
953
let ( blocks, local_decls) = self . source . basic_blocks_and_local_decls_mut ( ) ;
970
954
match candidate {
971
955
Candidate :: Ref ( loc) => {
@@ -1074,8 +1058,25 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
1074
1058
TerminatorKind :: Call { ref mut args, .. } => {
1075
1059
let ty = args[ index] . ty ( local_decls, self . tcx ) ;
1076
1060
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) )
1079
1080
}
1080
1081
// We expected a `TerminatorKind::Call` for which we'd like to promote an
1081
1082
// argument. `qualify_consts` saw a `TerminatorKind::Call` here, but
@@ -1085,7 +1086,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
1085
1086
// providing a value whose computation contains another call to a function
1086
1087
// requiring a constant argument.
1087
1088
TerminatorKind :: Goto { .. } => return None ,
1088
- _ => bug ! ( )
1089
+ _ => bug ! ( ) ,
1089
1090
}
1090
1091
}
1091
1092
}
0 commit comments