@@ -169,12 +169,12 @@ pub fn optimize_matches(lowered: &mut FlatLowered) {
169
169
fn statement_can_be_optimized_out (
170
170
stmt : & Statement ,
171
171
info : & mut AnalysisInfo < ' _ > ,
172
+ mut candidate : OptimizationCandidate < ' _ > ,
172
173
statement_location : ( BlockId , usize ) ,
173
174
) -> Option < FixInfo > {
174
175
let Statement :: EnumConstruct ( StatementEnumConstruct { variant, input, output } ) = stmt else {
175
176
return None ;
176
177
} ;
177
- let candidate = info. candidate . as_mut ( ) ?;
178
178
if * output != candidate. match_variable {
179
179
return None ;
180
180
}
@@ -198,7 +198,7 @@ fn statement_can_be_optimized_out(
198
198
// Compute the demand based on the demand of the specific arm, rather than the current demand
199
199
// (which contains the union of the demands from all the arms).
200
200
// Apply the remapping of the input variable and the additional remappings if exist.
201
- let mut demand = candidate. arm_demands [ arm_idx] . clone ( ) ;
201
+ let mut demand = std :: mem :: take ( & mut candidate. arm_demands [ arm_idx] ) ;
202
202
demand
203
203
. apply_remapping ( & mut EmptyDemandReporter { } , [ ( var_id, ( & input. var_id , ( ) ) ) ] . into_iter ( ) ) ;
204
204
@@ -218,8 +218,8 @@ fn statement_can_be_optimized_out(
218
218
arm_idx,
219
219
target_block : arm. block_id ,
220
220
remapping,
221
- reachable_blocks : candidate. arm_reachable_blocks [ arm_idx] . clone ( ) ,
222
- additional_remapping : candidate. additional_remappings . clone ( ) . unwrap_or_default ( ) ,
221
+ reachable_blocks : std :: mem :: take ( & mut candidate. arm_reachable_blocks [ arm_idx] ) ,
222
+ additional_remapping : candidate. additional_remappings . unwrap_or_default ( ) ,
223
223
} )
224
224
}
225
225
@@ -288,17 +288,20 @@ impl<'a> Analyzer<'a> for MatchOptimizerContext {
288
288
statement_location : StatementLocation ,
289
289
stmt : & Statement ,
290
290
) {
291
- if let Some ( fix_info) = statement_can_be_optimized_out ( stmt, info, statement_location) {
292
- self . fixes . push ( fix_info) ;
293
- } else {
294
- info. demand . variables_introduced ( & mut EmptyDemandReporter { } , stmt. outputs ( ) , ( ) ) ;
295
- info. demand . variables_used (
296
- & mut EmptyDemandReporter { } ,
297
- stmt. inputs ( ) . iter ( ) . map ( |VarUsage { var_id, .. } | ( var_id, ( ) ) ) ,
298
- ) ;
291
+ if let Some ( candidate) = std:: mem:: take ( & mut info. candidate ) {
292
+ if let Some ( fix_info) =
293
+ statement_can_be_optimized_out ( stmt, info, candidate, statement_location)
294
+ {
295
+ self . fixes . push ( fix_info) ;
296
+ return ;
297
+ }
299
298
}
300
299
301
- info. candidate = None ;
300
+ info. demand . variables_introduced ( & mut EmptyDemandReporter { } , stmt. outputs ( ) , ( ) ) ;
301
+ info. demand . variables_used (
302
+ & mut EmptyDemandReporter { } ,
303
+ stmt. inputs ( ) . iter ( ) . map ( |VarUsage { var_id, .. } | ( var_id, ( ) ) ) ,
304
+ ) ;
302
305
}
303
306
304
307
fn visit_goto (
0 commit comments