Skip to content

Commit d32c2f0

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

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

compiler/rustc_middle/src/mir/terminator.rs

+28-31
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ pub struct Terminator<'tcx> {
326326
}
327327

328328
pub type Successors<'a> = impl DoubleEndedIterator<Item = BasicBlock> + 'a;
329-
pub type SuccessorsMut<'a> =
330-
iter::Chain<std::option::IntoIter<&'a mut BasicBlock>, slice::IterMut<'a, BasicBlock>>;
329+
pub type SuccessorsMut<'a> = impl DoubleEndedIterator<Item = &'a mut BasicBlock> + 'a;
331330

332331
impl<'tcx> Terminator<'tcx> {
333332
pub fn successors(&self) -> Successors<'_> {
@@ -355,24 +354,24 @@ impl<'tcx> TerminatorKind<'tcx> {
355354
pub fn successors(&self) -> Successors<'_> {
356355
use self::TerminatorKind::*;
357356
match *self {
358-
Call { target: Some(t), unwind: UnwindAction::Cleanup(ref u), .. }
359-
| Yield { resume: t, drop: Some(ref u), .. }
360-
| Drop { target: t, unwind: UnwindAction::Cleanup(ref u), .. }
361-
| Assert { target: t, unwind: UnwindAction::Cleanup(ref u), .. }
362-
| FalseUnwind { real_target: t, unwind: UnwindAction::Cleanup(ref u) }
363-
| InlineAsm { destination: Some(t), unwind: UnwindAction::Cleanup(ref u), .. } => {
364-
Some(t).into_iter().chain(slice::from_ref(u).into_iter().copied())
365-
}
366-
Goto { target: t }
367-
| Call { target: None, unwind: UnwindAction::Cleanup(t), .. }
368-
| Call { target: Some(t), unwind: _, .. }
369-
| Yield { resume: t, drop: None, .. }
370-
| Drop { target: t, unwind: _, .. }
371-
| Assert { target: t, unwind: _, .. }
372-
| FalseUnwind { real_target: t, unwind: _ }
373-
| InlineAsm { destination: None, unwind: UnwindAction::Cleanup(t), .. }
374-
| InlineAsm { destination: Some(t), unwind: _, .. } => {
375-
Some(t).into_iter().chain((&[]).into_iter().copied())
357+
Call { target: Some(ref t), unwind: UnwindAction::Cleanup(u), .. }
358+
| Yield { resume: ref t, drop: Some(u), .. }
359+
| Drop { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
360+
| Assert { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
361+
| FalseUnwind { real_target: ref t, unwind: UnwindAction::Cleanup(u) }
362+
| InlineAsm { destination: Some(ref t), unwind: UnwindAction::Cleanup(u), .. } => {
363+
slice::from_ref(t).into_iter().copied().chain(Some(u))
364+
}
365+
Goto { target: ref t }
366+
| Call { target: None, unwind: UnwindAction::Cleanup(ref t), .. }
367+
| Call { target: Some(ref t), unwind: _, .. }
368+
| Yield { resume: ref t, drop: None, .. }
369+
| Drop { target: ref t, unwind: _, .. }
370+
| Assert { target: ref t, unwind: _, .. }
371+
| FalseUnwind { real_target: ref t, unwind: _ }
372+
| InlineAsm { destination: None, unwind: UnwindAction::Cleanup(ref t), .. }
373+
| InlineAsm { destination: Some(ref t), unwind: _, .. } => {
374+
slice::from_ref(t).into_iter().copied().chain(None)
376375
}
377376
UnwindResume
378377
| UnwindTerminate(_)
@@ -381,14 +380,12 @@ impl<'tcx> TerminatorKind<'tcx> {
381380
| Unreachable
382381
| Call { target: None, unwind: _, .. }
383382
| InlineAsm { destination: None, unwind: _, .. } => {
384-
None.into_iter().chain((&[]).into_iter().copied())
383+
(&[]).into_iter().copied().chain(None)
385384
}
386-
SwitchInt { ref targets, .. } => {
387-
None.into_iter().chain(targets.targets.iter().copied())
385+
SwitchInt { ref targets, .. } => targets.targets.iter().copied().chain(None),
386+
FalseEdge { ref real_target, imaginary_target } => {
387+
slice::from_ref(real_target).into_iter().copied().chain(Some(imaginary_target))
388388
}
389-
FalseEdge { real_target, ref imaginary_target } => Some(real_target)
390-
.into_iter()
391-
.chain(slice::from_ref(imaginary_target).into_iter().copied()),
392389
}
393390
}
394391

@@ -404,7 +401,7 @@ impl<'tcx> TerminatorKind<'tcx> {
404401
destination: Some(ref mut t),
405402
unwind: UnwindAction::Cleanup(ref mut u),
406403
..
407-
} => Some(t).into_iter().chain(slice::from_mut(u)),
404+
} => slice::from_mut(t).into_iter().chain(Some(u)),
408405
Goto { target: ref mut t }
409406
| Call { target: None, unwind: UnwindAction::Cleanup(ref mut t), .. }
410407
| Call { target: Some(ref mut t), unwind: _, .. }
@@ -414,18 +411,18 @@ impl<'tcx> TerminatorKind<'tcx> {
414411
| FalseUnwind { real_target: ref mut t, unwind: _ }
415412
| InlineAsm { destination: None, unwind: UnwindAction::Cleanup(ref mut t), .. }
416413
| InlineAsm { destination: Some(ref mut t), unwind: _, .. } => {
417-
Some(t).into_iter().chain(&mut [])
414+
slice::from_mut(t).into_iter().chain(None)
418415
}
419416
UnwindResume
420417
| UnwindTerminate(_)
421418
| CoroutineDrop
422419
| Return
423420
| Unreachable
424421
| Call { target: None, unwind: _, .. }
425-
| InlineAsm { destination: None, unwind: _, .. } => None.into_iter().chain(&mut []),
426-
SwitchInt { ref mut targets, .. } => None.into_iter().chain(&mut targets.targets),
422+
| InlineAsm { destination: None, unwind: _, .. } => (&mut []).into_iter().chain(None),
423+
SwitchInt { ref mut targets, .. } => targets.targets.iter_mut().chain(None),
427424
FalseEdge { ref mut real_target, ref mut imaginary_target } => {
428-
Some(real_target).into_iter().chain(slice::from_mut(imaginary_target))
425+
slice::from_mut(real_target).into_iter().chain(Some(imaginary_target))
429426
}
430427
}
431428
}

0 commit comments

Comments
 (0)