Skip to content

Commit 42baff8

Browse files
authored
Unrolled build for #148054
Rollup merge of #148054 - nnethercote:chain, r=saethlin Streamline iterator chaining when computing successors. There are numerous unnecessary `into_iter` calls. Also add a comment explaining why the code looks like this, because it's non-obvious at first glance. r? `@saethlin`
2 parents 38bc246 + 3d95159 commit 42baff8

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

compiler/rustc_middle/src/mir/terminator.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ pub use helper::*;
501501

502502
mod helper {
503503
use super::*;
504+
// Note: the methods below use a `slice.chain(Option).chain(Option)` pattern so that all paths
505+
// produce an iterator with the same concrete type.
504506
pub type Successors<'a> = impl DoubleEndedIterator<Item = BasicBlock> + 'a;
505507

506508
impl SwitchTargets {
@@ -510,7 +512,7 @@ mod helper {
510512
#[define_opaque(Successors)]
511513
pub fn successors_for_value(&self, value: u128) -> Successors<'_> {
512514
let target = self.target_for_value(value);
513-
(&[]).into_iter().copied().chain(Some(target).into_iter().chain(None))
515+
(&[]).into_iter().copied().chain(Some(target)).chain(None)
514516
}
515517
}
516518

@@ -522,10 +524,7 @@ mod helper {
522524
match *self {
523525
// 3-successors for async drop: target, unwind, dropline (parent coroutine drop)
524526
Drop { target: ref t, unwind: UnwindAction::Cleanup(u), drop: Some(d), .. } => {
525-
slice::from_ref(t)
526-
.into_iter()
527-
.copied()
528-
.chain(Some(u).into_iter().chain(Some(d)))
527+
slice::from_ref(t).into_iter().copied().chain(Some(u)).chain(Some(d))
529528
}
530529
// 2-successors
531530
Call { target: Some(ref t), unwind: UnwindAction::Cleanup(u), .. }
@@ -534,7 +533,7 @@ mod helper {
534533
| Drop { target: ref t, unwind: _, drop: Some(u), .. }
535534
| Assert { target: ref t, unwind: UnwindAction::Cleanup(u), .. }
536535
| FalseUnwind { real_target: ref t, unwind: UnwindAction::Cleanup(u) } => {
537-
slice::from_ref(t).into_iter().copied().chain(Some(u).into_iter().chain(None))
536+
slice::from_ref(t).into_iter().copied().chain(Some(u)).chain(None)
538537
}
539538
// single successor
540539
Goto { target: ref t }
@@ -544,7 +543,7 @@ mod helper {
544543
| Drop { target: ref t, unwind: _, .. }
545544
| Assert { target: ref t, unwind: _, .. }
546545
| FalseUnwind { real_target: ref t, unwind: _ } => {
547-
slice::from_ref(t).into_iter().copied().chain(None.into_iter().chain(None))
546+
slice::from_ref(t).into_iter().copied().chain(None).chain(None)
548547
}
549548
// No successors
550549
UnwindResume
@@ -554,23 +553,24 @@ mod helper {
554553
| Unreachable
555554
| TailCall { .. }
556555
| Call { target: None, unwind: _, .. } => {
557-
(&[]).into_iter().copied().chain(None.into_iter().chain(None))
556+
(&[]).into_iter().copied().chain(None).chain(None)
558557
}
559558
// Multiple successors
560559
InlineAsm { ref targets, unwind: UnwindAction::Cleanup(u), .. } => {
561-
targets.iter().copied().chain(Some(u).into_iter().chain(None))
560+
targets.iter().copied().chain(Some(u)).chain(None)
562561
}
563562
InlineAsm { ref targets, unwind: _, .. } => {
564-
targets.iter().copied().chain(None.into_iter().chain(None))
563+
targets.iter().copied().chain(None).chain(None)
565564
}
566565
SwitchInt { ref targets, .. } => {
567-
targets.targets.iter().copied().chain(None.into_iter().chain(None))
566+
targets.targets.iter().copied().chain(None).chain(None)
568567
}
569568
// FalseEdge
570569
FalseEdge { ref real_target, imaginary_target } => slice::from_ref(real_target)
571570
.into_iter()
572571
.copied()
573-
.chain(Some(imaginary_target).into_iter().chain(None)),
572+
.chain(Some(imaginary_target))
573+
.chain(None),
574574
}
575575
}
576576

0 commit comments

Comments
 (0)