@@ -118,11 +118,11 @@ impl Direction for Backward {
118
118
let targets =
119
119
values. iter ( ) . map ( |& value| SwitchIntTarget { value, target : block } ) ;
120
120
121
- let mut tmp = None ;
121
+ let mut tmp = analysis . bottom_value ( body ) ;
122
122
for target in targets {
123
- let tmp = opt_clone_from_or_clone ( & mut tmp , exit_state) ;
124
- analysis. apply_switch_int_edge_effect ( & mut data, tmp, target) ;
125
- propagate ( pred, tmp) ;
123
+ tmp. clone_from ( & exit_state) ;
124
+ analysis. apply_switch_int_edge_effect ( & mut data, & mut tmp, target) ;
125
+ propagate ( pred, & tmp) ;
126
126
}
127
127
} else {
128
128
propagate ( pred, exit_state)
@@ -251,7 +251,7 @@ impl Direction for Forward {
251
251
252
252
fn apply_effects_in_block < ' mir , ' tcx , A > (
253
253
analysis : & mut A ,
254
- _body : & mir:: Body < ' tcx > ,
254
+ body : & mir:: Body < ' tcx > ,
255
255
state : & mut A :: Domain ,
256
256
block : BasicBlock ,
257
257
block_data : & ' mir mir:: BasicBlockData < ' tcx > ,
@@ -292,14 +292,15 @@ impl Direction for Forward {
292
292
}
293
293
TerminatorEdges :: SwitchInt { targets, discr } => {
294
294
if let Some ( mut data) = analysis. get_switch_int_data ( block, discr) {
295
- let mut tmp = None ;
295
+ let mut tmp = analysis . bottom_value ( body ) ;
296
296
for ( value, target) in targets. iter ( ) {
297
- let tmp = opt_clone_from_or_clone ( & mut tmp, exit_state) ;
298
- analysis. apply_switch_int_edge_effect ( & mut data, tmp, SwitchIntTarget {
299
- value : Some ( value) ,
300
- target,
301
- } ) ;
302
- propagate ( target, tmp) ;
297
+ tmp. clone_from ( & exit_state) ;
298
+ analysis. apply_switch_int_edge_effect (
299
+ & mut data,
300
+ & mut tmp,
301
+ SwitchIntTarget { value : Some ( value) , target } ,
302
+ ) ;
303
+ propagate ( target, & tmp) ;
303
304
}
304
305
305
306
// Once we get to the final, "otherwise" branch, there is no need to preserve
@@ -425,21 +426,3 @@ impl Direction for Forward {
425
426
vis. visit_block_end ( state) ;
426
427
}
427
428
}
428
-
429
- /// An analogue of `Option::get_or_insert_with` that stores a clone of `val` into `opt`, but uses
430
- /// the more efficient `clone_from` if `opt` was `Some`.
431
- ///
432
- /// Returns a mutable reference to the new clone that resides in `opt`.
433
- //
434
- // FIXME: Figure out how to express this using `Option::clone_from`, or maybe lift it into the
435
- // standard library?
436
- fn opt_clone_from_or_clone < ' a , T : Clone > ( opt : & ' a mut Option < T > , val : & T ) -> & ' a mut T {
437
- if opt. is_some ( ) {
438
- let ret = opt. as_mut ( ) . unwrap ( ) ;
439
- ret. clone_from ( val) ;
440
- ret
441
- } else {
442
- * opt = Some ( val. clone ( ) ) ;
443
- opt. as_mut ( ) . unwrap ( )
444
- }
445
- }
0 commit comments