File tree 1 file changed +25
-3
lines changed
compiler/rustc_mir_transform/src
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>(
1060
1060
}
1061
1061
1062
1062
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;
1066
1063
1067
1064
let mut extra_statements = vec ! [ ] ;
1068
1065
// Visit candidates in reverse, in case they're nested.
@@ -1121,5 +1118,30 @@ fn promote_candidates<'tcx>(
1121
1118
body[ loc. block ] . statements . insert ( loc. statement_index , statement) ;
1122
1119
}
1123
1120
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
+
1124
1146
promotions
1125
1147
}
You can’t perform that action at this time.
0 commit comments