@@ -270,12 +270,13 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
270270 self . process_switch_int ( discr, targets, bb, & mut state) ;
271271 self . find_opportunity ( pred, state, cost, depth + 1 ) ;
272272 }
273- _ => self . recurse_through_terminator ( pred, & state, & cost, depth) ,
273+ _ => self . recurse_through_terminator ( pred, || state, & cost, depth) ,
274274 }
275- } else {
275+ } else if let & [ ref predecessors @ .. , last_pred ] = & predecessors [ .. ] {
276276 for & pred in predecessors {
277- self . recurse_through_terminator ( pred, & state, & cost, depth) ;
277+ self . recurse_through_terminator ( pred, || state. clone ( ) , & cost, depth) ;
278278 }
279+ self . recurse_through_terminator ( last_pred, || state, & cost, depth) ;
279280 }
280281
281282 let new_tos = & mut self . opportunities [ last_non_rec..] ;
@@ -566,11 +567,12 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
566567 None
567568 }
568569
569- #[ instrument( level = "trace" , skip( self , cost) ) ]
570+ #[ instrument( level = "trace" , skip( self , state , cost) ) ]
570571 fn recurse_through_terminator (
571572 & mut self ,
572573 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 > > ,
574576 cost : & CostChecker < ' _ , ' tcx > ,
575577 depth : usize ,
576578 ) {
@@ -600,7 +602,7 @@ impl<'tcx, 'a> TOFinder<'tcx, 'a> {
600602 } ;
601603
602604 // We can recurse through this terminator.
603- let mut state = state. clone ( ) ;
605+ let mut state = state ( ) ;
604606 if let Some ( place_to_flood) = place_to_flood {
605607 state. flood_with ( place_to_flood. as_ref ( ) , self . map , ConditionSet :: default ( ) ) ;
606608 }
0 commit comments