@@ -270,12 +270,13 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
270
270
self . process_switch_int ( discr, targets, bb, & mut state) ;
271
271
self . find_opportunity ( pred, state, cost, depth + 1 ) ;
272
272
}
273
- _ => self . recurse_through_terminator ( pred, & state, & cost, depth) ,
273
+ _ => self . recurse_through_terminator ( pred, || state, & cost, depth) ,
274
274
}
275
- } else {
275
+ } else if let & [ ref predecessors @ .. , last_pred ] = & predecessors [ .. ] {
276
276
for & pred in predecessors {
277
- self . recurse_through_terminator ( pred, & state, & cost, depth) ;
277
+ self . recurse_through_terminator ( pred, || state. clone ( ) , & cost, depth) ;
278
278
}
279
+ self . recurse_through_terminator ( last_pred, || state, & cost, depth) ;
279
280
}
280
281
281
282
let new_tos = & mut self . opportunities [ last_non_rec..] ;
@@ -566,11 +567,12 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
566
567
None
567
568
}
568
569
569
- #[ instrument( level = "trace" , skip( self , cost) ) ]
570
+ #[ instrument( level = "trace" , skip( self , state , cost) ) ]
570
571
fn recurse_through_terminator (
571
572
& mut self ,
572
573
bb : BasicBlock ,
573
- state : & State < ConditionSet < ' a > > ,
574
+ // Pass a closure that may clone the state, as we don't want to do it each time.
575
+ state : impl FnOnce ( ) -> State < ConditionSet < ' a > > ,
574
576
cost : & CostChecker < ' _ , ' tcx > ,
575
577
depth : usize ,
576
578
) {
@@ -600,7 +602,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
600
602
} ;
601
603
602
604
// We can recurse through this terminator.
603
- let mut state = state. clone ( ) ;
605
+ let mut state = state ( ) ;
604
606
if let Some ( place_to_flood) = place_to_flood {
605
607
state. flood_with ( place_to_flood. as_ref ( ) , self . map , ConditionSet :: default ( ) ) ;
606
608
}
0 commit comments