Skip to content

Commit 7152993

Browse files
committed
Use slice.chain(option) for Successors
This makes more sense because most cases then second one is unwind target.
1 parent 040ab7d commit 7152993

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

compiler/rustc_middle/src/mir/terminator.rs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ pub struct Terminator<'tcx> {
336336
}
337337

338338
pub type Successors<'a> = impl DoubleEndedIterator<Item = BasicBlock> + 'a;
339-
pub type SuccessorsMut<'a> =
340-
iter::Chain<std::option::IntoIter<&'a mut BasicBlock>, slice::IterMut<'a, BasicBlock>>;
339+
pub type SuccessorsMut<'a> = impl DoubleEndedIterator<Item = &'a mut BasicBlock> + 'a;
341340

342341
impl<'tcx> Terminator<'tcx> {
343342
#[inline]
@@ -371,24 +370,24 @@ impl<'tcx> TerminatorKind<'tcx> {
371370
pub fn successors(&self) -> Successors<'_> {
372371
use self::TerminatorKind::*;
373372
match *self {
374-
Call { target: Some(t), unwind: UnwindAction::Cleanup(ref u), .. }
375-
| Yield { resume: t, drop: Some(ref u), .. }
376-
| Drop { target: t, unwind: UnwindAction::Cleanup(ref u), .. }
377-
| Assert { target: t, unwind: UnwindAction::Cleanup(ref u), .. }
378-
| FalseUnwind { real_target: t, unwind: UnwindAction::Cleanup(ref u) }
379-
| InlineAsm { destination: Some(t), unwind: UnwindAction::Cleanup(ref u), .. } => {
380-
Some(t).into_iter().chain(slice::from_ref(u).into_iter().copied())
381-
}
382-
Goto { target: t }
383-
| Call { target: None, unwind: UnwindAction::Cleanup(t), .. }
384-
| Call { target: Some(t), unwind: _, .. }
385-
| Yield { resume: t, drop: None, .. }
386-
| Drop { target: t, unwind: _, .. }
387-
| Assert { target: t, unwind: _, .. }
388-
| FalseUnwind { real_target: t, unwind: _ }
389-
| InlineAsm { destination: None, unwind: UnwindAction::Cleanup(t), .. }
390-
| InlineAsm { destination: Some(t), unwind: _, .. } => {
391-
Some(t).into_iter().chain((&[]).into_iter().copied())
373+
Call { target: Some(ref t), unwind: UnwindAction::Cleanup(u), .. }
374+
| Yield { resume: ref t, drop: Some(u), .. }
375+
| Drop { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
376+
| Assert { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
377+
| FalseUnwind { real_target: ref t, unwind: UnwindAction::Cleanup(u) }
378+
| InlineAsm { destination: Some(ref t), unwind: UnwindAction::Cleanup(u), .. } => {
379+
slice::from_ref(t).into_iter().copied().chain(Some(u))
380+
}
381+
Goto { target: ref t }
382+
| Call { target: None, unwind: UnwindAction::Cleanup(ref t), .. }
383+
| Call { target: Some(ref t), unwind: _, .. }
384+
| Yield { resume: ref t, drop: None, .. }
385+
| Drop { target: ref t, unwind: _, .. }
386+
| Assert { target: ref t, unwind: _, .. }
387+
| FalseUnwind { real_target: ref t, unwind: _ }
388+
| InlineAsm { destination: None, unwind: UnwindAction::Cleanup(ref t), .. }
389+
| InlineAsm { destination: Some(ref t), unwind: _, .. } => {
390+
slice::from_ref(t).into_iter().copied().chain(None)
392391
}
393392
UnwindResume
394393
| UnwindTerminate(_)
@@ -397,14 +396,12 @@ impl<'tcx> TerminatorKind<'tcx> {
397396
| Unreachable
398397
| Call { target: None, unwind: _, .. }
399398
| InlineAsm { destination: None, unwind: _, .. } => {
400-
None.into_iter().chain((&[]).into_iter().copied())
399+
(&[]).into_iter().copied().chain(None)
401400
}
402-
SwitchInt { ref targets, .. } => {
403-
None.into_iter().chain(targets.targets.iter().copied())
401+
SwitchInt { ref targets, .. } => targets.targets.iter().copied().chain(None),
402+
FalseEdge { ref real_target, imaginary_target } => {
403+
slice::from_ref(real_target).into_iter().copied().chain(Some(imaginary_target))
404404
}
405-
FalseEdge { real_target, ref imaginary_target } => Some(real_target)
406-
.into_iter()
407-
.chain(slice::from_ref(imaginary_target).into_iter().copied()),
408405
}
409406
}
410407

@@ -421,7 +418,7 @@ impl<'tcx> TerminatorKind<'tcx> {
421418
destination: Some(ref mut t),
422419
unwind: UnwindAction::Cleanup(ref mut u),
423420
..
424-
} => Some(t).into_iter().chain(slice::from_mut(u)),
421+
} => slice::from_mut(t).into_iter().chain(Some(u)),
425422
Goto { target: ref mut t }
426423
| Call { target: None, unwind: UnwindAction::Cleanup(ref mut t), .. }
427424
| Call { target: Some(ref mut t), unwind: _, .. }
@@ -431,18 +428,18 @@ impl<'tcx> TerminatorKind<'tcx> {
431428
| FalseUnwind { real_target: ref mut t, unwind: _ }
432429
| InlineAsm { destination: None, unwind: UnwindAction::Cleanup(ref mut t), .. }
433430
| InlineAsm { destination: Some(ref mut t), unwind: _, .. } => {
434-
Some(t).into_iter().chain(&mut [])
431+
slice::from_mut(t).into_iter().chain(None)
435432
}
436433
UnwindResume
437434
| UnwindTerminate(_)
438435
| CoroutineDrop
439436
| Return
440437
| Unreachable
441438
| Call { target: None, unwind: _, .. }
442-
| InlineAsm { destination: None, unwind: _, .. } => None.into_iter().chain(&mut []),
443-
SwitchInt { ref mut targets, .. } => None.into_iter().chain(&mut targets.targets),
439+
| InlineAsm { destination: None, unwind: _, .. } => (&mut []).into_iter().chain(None),
440+
SwitchInt { ref mut targets, .. } => targets.targets.iter_mut().chain(None),
444441
FalseEdge { ref mut real_target, ref mut imaginary_target } => {
445-
Some(real_target).into_iter().chain(slice::from_mut(imaginary_target))
442+
slice::from_mut(real_target).into_iter().chain(Some(imaginary_target))
446443
}
447444
}
448445
}

0 commit comments

Comments
 (0)