@@ -950,6 +950,23 @@ 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_operand = |ty, span| {
954
+ promoted. span = span;
955
+ promoted. local_decls [ RETURN_PLACE ] = LocalDecl :: new_return_place ( ty, span) ;
956
+
957
+ Operand :: Constant ( Box :: new ( Constant {
958
+ span,
959
+ user_ty : None ,
960
+ literal : tcx. mk_const ( ty:: Const {
961
+ ty,
962
+ val : ty:: ConstKind :: Unevaluated (
963
+ def_id,
964
+ InternalSubsts :: identity_for_item ( tcx, def_id) ,
965
+ Some ( promoted_id) ,
966
+ ) ,
967
+ } ) ,
968
+ } ) )
969
+ } ;
953
970
let ( blocks, local_decls) = self . source . basic_blocks_and_local_decls_mut ( ) ;
954
971
match candidate {
955
972
Candidate :: Ref ( loc) => {
@@ -968,10 +985,6 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
968
985
ty:: TypeAndMut { ty, mutbl : borrow_kind. to_mutbl_lossy ( ) } ,
969
986
) ;
970
987
971
- promoted. span = span;
972
- promoted. local_decls [ RETURN_PLACE ] =
973
- LocalDecl :: new_return_place ( ref_ty, span) ;
974
-
975
988
* region = tcx. lifetimes . re_static ;
976
989
977
990
let mut projection = vec ! [ PlaceElem :: Deref ] ;
@@ -986,24 +999,11 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
986
999
let promoted_ref = local_decls. push ( promoted_ref) ;
987
1000
assert_eq ! ( self . temps. push( TempState :: Unpromotable ) , promoted_ref) ;
988
1001
989
- let promoted_ref_rvalue =
990
- Rvalue :: Use ( Operand :: Constant ( Box :: new ( Constant {
991
- span,
992
- user_ty : None ,
993
- literal : tcx. mk_const ( ty:: Const {
994
- ty : ref_ty,
995
- val : ty:: ConstKind :: Unevaluated (
996
- def_id,
997
- InternalSubsts :: identity_for_item ( tcx, def_id) ,
998
- Some ( promoted_id) ,
999
- ) ,
1000
- } ) ,
1001
- } ) ) ) ;
1002
1002
let promoted_ref_statement = Statement {
1003
1003
source_info : statement. source_info ,
1004
1004
kind : StatementKind :: Assign ( Box :: new ( (
1005
1005
Place :: from ( promoted_ref) ,
1006
- promoted_ref_rvalue ,
1006
+ Rvalue :: Use ( promoted_operand ( ref_ty , span ) ) ,
1007
1007
) ) ) ,
1008
1008
} ;
1009
1009
self . extra_statements . push ( ( loc, promoted_ref_statement) ) ;
@@ -1030,24 +1030,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
1030
1030
let ty = operand. ty ( local_decls, self . tcx ) ;
1031
1031
let span = statement. source_info . span ;
1032
1032
1033
- promoted. span = span;
1034
- promoted. local_decls [ RETURN_PLACE ] =
1035
- LocalDecl :: new_return_place ( ty, span) ;
1036
-
1037
- let promoted_operand = Operand :: Constant ( Box :: new ( Constant {
1038
- span,
1039
- user_ty : None ,
1040
- literal : tcx. mk_const ( ty:: Const {
1041
- ty,
1042
- val : ty:: ConstKind :: Unevaluated (
1043
- def_id,
1044
- InternalSubsts :: identity_for_item ( tcx, def_id) ,
1045
- Some ( promoted_id) ,
1046
- ) ,
1047
- } ) ,
1048
- } ) ) ;
1049
-
1050
- Rvalue :: Use ( mem:: replace ( operand, promoted_operand) )
1033
+ Rvalue :: Use ( mem:: replace ( operand, promoted_operand ( ty, span) ) )
1051
1034
}
1052
1035
_ => bug ! ( ) ,
1053
1036
}
@@ -1059,24 +1042,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
1059
1042
let ty = args[ index] . ty ( local_decls, self . tcx ) ;
1060
1043
let span = terminator. source_info . span ;
1061
1044
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) )
1045
+ Rvalue :: Use ( mem:: replace ( & mut args[ index] , promoted_operand ( ty, span) ) )
1080
1046
}
1081
1047
// We expected a `TerminatorKind::Call` for which we'd like to promote an
1082
1048
// argument. `qualify_consts` saw a `TerminatorKind::Call` here, but
@@ -1093,10 +1059,10 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
1093
1059
} ;
1094
1060
1095
1061
assert_eq ! ( self . new_block( ) , START_BLOCK ) ;
1096
- self . visit_rvalue ( & mut rvalue , Location {
1097
- block : BasicBlock :: new ( 0 ) ,
1098
- statement_index : usize:: MAX
1099
- } ) ;
1062
+ self . visit_rvalue (
1063
+ & mut rvalue ,
1064
+ Location { block : BasicBlock :: new ( 0 ) , statement_index : usize:: MAX } ,
1065
+ ) ;
1100
1066
1101
1067
let span = self . promoted . span ;
1102
1068
self . assign ( RETURN_PLACE , rvalue, span) ;
0 commit comments