@@ -908,6 +908,23 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
908
908
let promoted = & mut self . promoted ;
909
909
let promoted_id = Promoted :: new ( next_promoted_id) ;
910
910
let tcx = self . tcx ;
911
+ let mut promoted_operand = |ty, span| {
912
+ promoted. span = span;
913
+ promoted. local_decls [ RETURN_PLACE ] = LocalDecl :: new_return_place ( ty, span) ;
914
+
915
+ Operand :: Constant ( Box :: new ( Constant {
916
+ span,
917
+ user_ty : None ,
918
+ literal : tcx. mk_const ( ty:: Const {
919
+ ty,
920
+ val : ty:: ConstKind :: Unevaluated (
921
+ def_id,
922
+ InternalSubsts :: identity_for_item ( tcx, def_id) ,
923
+ Some ( promoted_id) ,
924
+ ) ,
925
+ } ) ,
926
+ } ) )
927
+ } ;
911
928
let ( blocks, local_decls) = self . source . basic_blocks_and_local_decls_mut ( ) ;
912
929
match candidate {
913
930
Candidate :: Ref ( loc) => {
@@ -926,10 +943,6 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
926
943
ty:: TypeAndMut { ty, mutbl : borrow_kind. to_mutbl_lossy ( ) } ,
927
944
) ;
928
945
929
- promoted. span = span;
930
- promoted. local_decls [ RETURN_PLACE ] =
931
- LocalDecl :: new_return_place ( ref_ty, span) ;
932
-
933
946
* region = tcx. lifetimes . re_static ;
934
947
935
948
let mut projection = vec ! [ PlaceElem :: Deref ] ;
@@ -944,24 +957,11 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
944
957
let promoted_ref = local_decls. push ( promoted_ref) ;
945
958
assert_eq ! ( self . temps. push( TempState :: Unpromotable ) , promoted_ref) ;
946
959
947
- let promoted_ref_rvalue =
948
- Rvalue :: Use ( Operand :: Constant ( Box :: new ( Constant {
949
- span,
950
- user_ty : None ,
951
- literal : tcx. mk_const ( ty:: Const {
952
- ty : ref_ty,
953
- val : ty:: ConstKind :: Unevaluated (
954
- def_id,
955
- InternalSubsts :: identity_for_item ( tcx, def_id) ,
956
- Some ( promoted_id) ,
957
- ) ,
958
- } ) ,
959
- } ) ) ) ;
960
960
let promoted_ref_statement = Statement {
961
961
source_info : statement. source_info ,
962
962
kind : StatementKind :: Assign ( Box :: new ( (
963
963
Place :: from ( promoted_ref) ,
964
- promoted_ref_rvalue ,
964
+ Rvalue :: Use ( promoted_operand ( ref_ty , span ) ) ,
965
965
) ) ) ,
966
966
} ;
967
967
self . extra_statements . push ( ( loc, promoted_ref_statement) ) ;
@@ -988,24 +988,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
988
988
let ty = operand. ty ( local_decls, self . tcx ) ;
989
989
let span = statement. source_info . span ;
990
990
991
- promoted. span = span;
992
- promoted. local_decls [ RETURN_PLACE ] =
993
- LocalDecl :: new_return_place ( ty, span) ;
994
-
995
- let promoted_operand = Operand :: Constant ( Box :: new ( Constant {
996
- span,
997
- user_ty : None ,
998
- literal : tcx. mk_const ( ty:: Const {
999
- ty,
1000
- val : ty:: ConstKind :: Unevaluated (
1001
- def_id,
1002
- InternalSubsts :: identity_for_item ( tcx, def_id) ,
1003
- Some ( promoted_id) ,
1004
- ) ,
1005
- } ) ,
1006
- } ) ) ;
1007
-
1008
- Rvalue :: Use ( mem:: replace ( operand, promoted_operand) )
991
+ Rvalue :: Use ( mem:: replace ( operand, promoted_operand ( ty, span) ) )
1009
992
}
1010
993
_ => bug ! ( ) ,
1011
994
}
@@ -1017,24 +1000,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
1017
1000
let ty = args[ index] . ty ( local_decls, self . tcx ) ;
1018
1001
let span = terminator. source_info . span ;
1019
1002
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) )
1003
+ Rvalue :: Use ( mem:: replace ( & mut args[ index] , promoted_operand ( ty, span) ) )
1038
1004
}
1039
1005
// We expected a `TerminatorKind::Call` for which we'd like to promote an
1040
1006
// argument. `qualify_consts` saw a `TerminatorKind::Call` here, but
0 commit comments