@@ -437,8 +437,8 @@ impl<'tcx> Terminator<'tcx> {
437
437
}
438
438
439
439
#[ inline]
440
- pub fn successors_mut ( & mut self ) -> SuccessorsMut < ' _ > {
441
- self . kind . successors_mut ( )
440
+ pub fn successors_mut < ' a > ( & ' a mut self , f : impl FnMut ( & ' a mut BasicBlock ) ) {
441
+ self . kind . successors_mut ( f )
442
442
}
443
443
444
444
#[ inline]
@@ -486,7 +486,6 @@ pub use helper::*;
486
486
mod helper {
487
487
use super :: * ;
488
488
pub type Successors < ' a > = impl DoubleEndedIterator < Item = BasicBlock > + ' a ;
489
- pub type SuccessorsMut < ' a > = impl DoubleEndedIterator < Item = & ' a mut BasicBlock > + ' a ;
490
489
491
490
impl SwitchTargets {
492
491
/// Like [`SwitchTargets::target_for_value`], but returning the same type as
@@ -560,69 +559,63 @@ mod helper {
560
559
}
561
560
562
561
#[ inline]
563
- #[ define_opaque( SuccessorsMut ) ]
564
- pub fn successors_mut ( & mut self ) -> SuccessorsMut < ' _ > {
562
+ pub fn successors_mut < ' a > ( & ' a mut self , mut f : impl FnMut ( & ' a mut BasicBlock ) ) {
565
563
use self :: TerminatorKind :: * ;
566
- match * self {
567
- // 3-successors for async drop: target, unwind, dropline (parent coroutine drop)
568
- Drop {
569
- target : ref mut t,
570
- unwind : UnwindAction :: Cleanup ( ref mut u) ,
571
- drop : Some ( ref mut d) ,
572
- ..
573
- } => slice:: from_mut ( t) . into_iter ( ) . chain ( Some ( u) . into_iter ( ) . chain ( Some ( d) ) ) ,
574
- // 2-successors
575
- Call {
576
- target : Some ( ref mut t) , unwind : UnwindAction :: Cleanup ( ref mut u) , ..
564
+ match self {
565
+ Drop { target, unwind, drop, .. } => {
566
+ f ( target) ;
567
+ if let UnwindAction :: Cleanup ( u) = unwind {
568
+ f ( u)
569
+ }
570
+ if let Some ( d) = drop {
571
+ f ( d)
572
+ }
573
+ }
574
+ Call { target, unwind, .. } => {
575
+ if let Some ( target) = target {
576
+ f ( target) ;
577
+ }
578
+ if let UnwindAction :: Cleanup ( u) = unwind {
579
+ f ( u)
580
+ }
577
581
}
578
- | Yield { resume : ref mut t, drop : Some ( ref mut u) , .. }
579
- | Drop {
580
- target : ref mut t,
581
- unwind : UnwindAction :: Cleanup ( ref mut u) ,
582
- drop : None ,
583
- ..
582
+ Yield { resume, drop, .. } => {
583
+ f ( resume) ;
584
+ if let Some ( d) = drop {
585
+ f ( d)
586
+ }
584
587
}
585
- | Drop { target : ref mut t, unwind : _, drop : Some ( ref mut u) , .. }
586
- | Assert { target : ref mut t, unwind : UnwindAction :: Cleanup ( ref mut u) , .. }
587
- | FalseUnwind {
588
- real_target : ref mut t,
589
- unwind : UnwindAction :: Cleanup ( ref mut u) ,
590
- } => slice:: from_mut ( t) . into_iter ( ) . chain ( Some ( u) . into_iter ( ) . chain ( None ) ) ,
591
- // single successor
592
- Goto { target : ref mut t }
593
- | Call { target : None , unwind : UnwindAction :: Cleanup ( ref mut t) , .. }
594
- | Call { target : Some ( ref mut t) , unwind : _, .. }
595
- | Yield { resume : ref mut t, drop : None , .. }
596
- | Drop { target : ref mut t, unwind : _, .. }
597
- | Assert { target : ref mut t, unwind : _, .. }
598
- | FalseUnwind { real_target : ref mut t, unwind : _ } => {
599
- slice:: from_mut ( t) . into_iter ( ) . chain ( None . into_iter ( ) . chain ( None ) )
588
+ Assert { target, unwind, .. } | FalseUnwind { real_target : target, unwind } => {
589
+ f ( target) ;
590
+ if let UnwindAction :: Cleanup ( u) = unwind {
591
+ f ( u)
592
+ }
593
+ }
594
+ Goto { target } => {
595
+ f ( target) ;
600
596
}
601
- // No successors
602
597
UnwindResume
603
598
| UnwindTerminate ( _)
604
599
| CoroutineDrop
605
600
| Return
606
601
| Unreachable
607
- | TailCall { .. }
608
- | Call { target : None , unwind : _, .. } => {
609
- ( & mut [ ] ) . into_iter ( ) . chain ( None . into_iter ( ) . chain ( None ) )
610
- }
611
- // Multiple successors
612
- InlineAsm { ref mut targets, unwind : UnwindAction :: Cleanup ( ref mut u) , .. } => {
613
- targets. iter_mut ( ) . chain ( Some ( u) . into_iter ( ) . chain ( None ) )
614
- }
615
- InlineAsm { ref mut targets, unwind : _, .. } => {
616
- targets. iter_mut ( ) . chain ( None . into_iter ( ) . chain ( None ) )
602
+ | TailCall { .. } => { }
603
+ InlineAsm { targets, unwind, .. } => {
604
+ for target in targets {
605
+ f ( target) ;
606
+ }
607
+ if let UnwindAction :: Cleanup ( u) = unwind {
608
+ f ( u)
609
+ }
617
610
}
618
- SwitchInt { ref mut targets, .. } => {
619
- targets. targets . iter_mut ( ) . chain ( None . into_iter ( ) . chain ( None ) )
611
+ SwitchInt { targets, .. } => {
612
+ for target in & mut targets. targets {
613
+ f ( target) ;
614
+ }
620
615
}
621
- // FalseEdge
622
- FalseEdge { ref mut real_target, ref mut imaginary_target } => {
623
- slice:: from_mut ( real_target)
624
- . into_iter ( )
625
- . chain ( Some ( imaginary_target) . into_iter ( ) . chain ( None ) )
616
+ FalseEdge { real_target, imaginary_target } => {
617
+ f ( real_target) ;
618
+ f ( imaginary_target) ;
626
619
}
627
620
}
628
621
}
0 commit comments