This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +25
-3
lines changed
compiler/rustc_mir_transform/src Expand file tree Collapse file tree 1 file changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -1060,9 +1060,6 @@ fn promote_candidates<'tcx>(
10601060 }
10611061
10621062 let mut promotions = IndexVec :: new ( ) ;
1063- // FIXME: buggy things, there shouldn't be more than 42 promoted items by PromoteTemps.
1064- // cannot check body.source.promoted,maybe stealed
1065- // let already = 0;
10661063
10671064 let mut extra_statements = vec ! [ ] ;
10681065 // Visit candidates in reverse, in case they're nested.
@@ -1121,5 +1118,30 @@ fn promote_candidates<'tcx>(
11211118 body[ loc. block ] . statements . insert ( loc. statement_index , statement) ;
11221119 }
11231120
1121+ // Eliminate assignments to, and drops of promoted temps.
1122+ let is_promoted_out = |index : Local | temps[ index] == TempState :: PromotedOut ;
1123+ for block in body. basic_blocks_mut ( ) {
1124+ block. statements . retain ( |statement| match & statement. kind {
1125+ StatementKind :: Assign ( box (
1126+ place,
1127+ Rvalue :: Use ( Operand :: Constant ( box ConstOperand {
1128+ const_ : Const :: Val ( _, ty) , ..
1129+ } ) ) ,
1130+ ) ) => {
1131+ if ty. is_unit ( )
1132+ && let Some ( index) = place. as_local ( )
1133+ {
1134+ !is_promoted_out ( index)
1135+ } else {
1136+ true
1137+ }
1138+ }
1139+ StatementKind :: StorageLive ( index) | StatementKind :: StorageDead ( index) => {
1140+ !is_promoted_out ( * index)
1141+ }
1142+ _ => true ,
1143+ } ) ;
1144+ }
1145+
11241146 promotions
11251147}
You can’t perform that action at this time.
0 commit comments