Skip to content

Commit 38bf115

Browse files
committed
Change Successors to impl Iterator<Item = BasicBlock>
1 parent 56d540e commit 38bf115

File tree

18 files changed

+54
-55
lines changed

18 files changed

+54
-55
lines changed

compiler/rustc_borrowck/src/dataflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'tcx> OutOfScopePrecomputer<'_, 'tcx> {
199199
// Add successor BBs to the work list, if necessary.
200200
let bb_data = &self.body[bb];
201201
debug_assert!(hi == bb_data.statements.len());
202-
for &succ_bb in bb_data.terminator().successors() {
202+
for succ_bb in bb_data.terminator().successors() {
203203
if !self.visited.insert(succ_bb) {
204204
if succ_bb == location.block && first_lo > 0 {
205205
// `succ_bb` has been seen before. If it wasn't

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
467467
block
468468
.terminator()
469469
.successors()
470-
.map(|bb| Location { statement_index: 0, block: *bb })
470+
.map(|bb| Location { statement_index: 0, block: bb })
471471
.filter(|s| visited_locations.insert(*s))
472472
.map(|s| {
473473
if self.is_back_edge(location, s) {
@@ -526,7 +526,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
526526
}
527527
} else {
528528
for bb in block.terminator().successors() {
529-
let successor = Location { statement_index: 0, block: *bb };
529+
let successor = Location { statement_index: 0, block: bb };
530530

531531
if !visited_locations.contains(&successor)
532532
&& self.find_loop_head_dfs(successor, loop_head, visited_locations)

compiler/rustc_borrowck/src/diagnostics/find_use.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ impl<'cx, 'tcx> UseFinder<'cx, 'tcx> {
6767
block_data
6868
.terminator()
6969
.successors()
70-
.filter(|&bb| Some(&Some(*bb)) != block_data.terminator().unwind())
71-
.map(|&bb| Location { statement_index: 0, block: bb }),
70+
.filter(|&bb| Some(&Some(bb)) != block_data.terminator().unwind())
71+
.map(|bb| Location { statement_index: 0, block: bb }),
7272
);
7373
}
7474
}

compiler/rustc_borrowck/src/nll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn populate_polonius_move_facts(
108108
// We are at the terminator of an init that has a panic path,
109109
// and where the init should not happen on panic
110110

111-
for &successor in block_data.terminator().successors() {
111+
for successor in block_data.terminator().successors() {
112112
if body[successor].is_cleanup {
113113
continue;
114114
}

compiler/rustc_codegen_ssa/src/mir/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKi
328328
bb, data, result[bb], funclet
329329
);
330330

331-
for &succ in data.terminator().successors() {
331+
for succ in data.terminator().successors() {
332332
let kind = result[succ];
333333
debug!("cleanup_kinds: propagating {:?} to {:?}/{:?}", funclet, succ, kind);
334334
match kind {

compiler/rustc_middle/src/mir/generic_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn mir_fn_to_generic_graph<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Grap
2424
let terminator = body[source].terminator();
2525
let labels = terminator.kind.fmt_successor_labels();
2626

27-
for (&target, label) in terminator.successors().zip(labels) {
27+
for (target, label) in terminator.successors().zip(labels) {
2828
let src = node(def_id, source);
2929
let trg = node(def_id, target);
3030
edges.push(Edge::new(src, trg, label.to_string()));

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,10 +1355,7 @@ pub enum InlineAsmOperand<'tcx> {
13551355
/// Type for MIR `Assert` terminator error messages.
13561356
pub type AssertMessage<'tcx> = AssertKind<Operand<'tcx>>;
13571357

1358-
// FIXME: Change `Successors` to `impl Iterator<Item = BasicBlock>`.
1359-
#[allow(rustc::pass_by_value)]
1360-
pub type Successors<'a> =
1361-
iter::Chain<option::IntoIter<&'a BasicBlock>, slice::Iter<'a, BasicBlock>>;
1358+
pub type Successors<'a> = impl Iterator<Item = BasicBlock> + 'a;
13621359
pub type SuccessorsMut<'a> =
13631360
iter::Chain<option::IntoIter<&'a mut BasicBlock>, slice::IterMut<'a, BasicBlock>>;
13641361

@@ -3434,13 +3431,13 @@ impl<'tcx> graph::WithStartNode for Body<'tcx> {
34343431
impl<'tcx> graph::WithSuccessors for Body<'tcx> {
34353432
#[inline]
34363433
fn successors(&self, node: Self::Node) -> <Self as GraphSuccessors<'_>>::Iter {
3437-
self.basic_blocks[node].terminator().successors().cloned()
3434+
self.basic_blocks[node].terminator().successors()
34383435
}
34393436
}
34403437

34413438
impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> {
34423439
type Item = BasicBlock;
3443-
type Iter = iter::Cloned<Successors<'b>>;
3440+
type Iter = Successors<'b>;
34443441
}
34453442

34463443
impl<'tcx, 'graph> graph::GraphPredecessors<'graph> for Body<'tcx> {

compiler/rustc_middle/src/mir/patch.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ impl<'tcx> MirPatch<'tcx> {
166166
// get terminator's targets and apply the statement to all of them.
167167
if loc.statement_index > body[loc.block].statements.len() {
168168
let term = body[loc.block].terminator();
169-
let successors = term.successors().clone();
170-
171-
for i in successors {
169+
for i in term.successors() {
172170
stmts_and_targets
173171
.push((Statement { source_info, kind: stmt.clone() }, i.clone()));
174172
}

compiler/rustc_middle/src/mir/predecessors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl PredecessorCache {
4343
let mut preds = IndexVec::from_elem(SmallVec::new(), basic_blocks);
4444
for (bb, data) in basic_blocks.iter_enumerated() {
4545
if let Some(term) = &data.terminator {
46-
for &succ in term.successors() {
46+
for succ in term.successors() {
4747
preds[succ].push(bb);
4848
}
4949
}

compiler/rustc_middle/src/mir/terminator.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -416,32 +416,36 @@ impl<'tcx> TerminatorKind<'tcx> {
416416
| Return
417417
| Unreachable
418418
| Call { destination: None, cleanup: None, .. }
419-
| InlineAsm { destination: None, cleanup: None, .. } => None.into_iter().chain(&[]),
420-
Goto { target: ref t }
421-
| Call { destination: None, cleanup: Some(ref t), .. }
422-
| Call { destination: Some((_, ref t)), cleanup: None, .. }
423-
| Yield { resume: ref t, drop: None, .. }
424-
| DropAndReplace { target: ref t, unwind: None, .. }
425-
| Drop { target: ref t, unwind: None, .. }
426-
| Assert { target: ref t, cleanup: None, .. }
427-
| FalseUnwind { real_target: ref t, unwind: None }
428-
| InlineAsm { destination: Some(ref t), cleanup: None, .. }
429-
| InlineAsm { destination: None, cleanup: Some(ref t), .. } => {
430-
Some(t).into_iter().chain(&[])
419+
| InlineAsm { destination: None, cleanup: None, .. } => {
420+
None.into_iter().chain((&[]).into_iter().copied())
431421
}
432-
Call { destination: Some((_, ref t)), cleanup: Some(ref u), .. }
433-
| Yield { resume: ref t, drop: Some(ref u), .. }
434-
| DropAndReplace { target: ref t, unwind: Some(ref u), .. }
435-
| Drop { target: ref t, unwind: Some(ref u), .. }
436-
| Assert { target: ref t, cleanup: Some(ref u), .. }
437-
| FalseUnwind { real_target: ref t, unwind: Some(ref u) }
438-
| InlineAsm { destination: Some(ref t), cleanup: Some(ref u), .. } => {
439-
Some(t).into_iter().chain(slice::from_ref(u))
422+
Goto { target: t }
423+
| Call { destination: None, cleanup: Some(t), .. }
424+
| Call { destination: Some((_, t)), cleanup: None, .. }
425+
| Yield { resume: t, drop: None, .. }
426+
| DropAndReplace { target: t, unwind: None, .. }
427+
| Drop { target: t, unwind: None, .. }
428+
| Assert { target: t, cleanup: None, .. }
429+
| FalseUnwind { real_target: t, unwind: None }
430+
| InlineAsm { destination: Some(t), cleanup: None, .. }
431+
| InlineAsm { destination: None, cleanup: Some(t), .. } => {
432+
Some(t).into_iter().chain((&[]).into_iter().copied())
440433
}
441-
SwitchInt { ref targets, .. } => None.into_iter().chain(&targets.targets),
442-
FalseEdge { ref real_target, ref imaginary_target } => {
443-
Some(real_target).into_iter().chain(slice::from_ref(imaginary_target))
434+
Call { destination: Some((_, t)), cleanup: Some(ref u), .. }
435+
| Yield { resume: t, drop: Some(ref u), .. }
436+
| DropAndReplace { target: t, unwind: Some(ref u), .. }
437+
| Drop { target: t, unwind: Some(ref u), .. }
438+
| Assert { target: t, cleanup: Some(ref u), .. }
439+
| FalseUnwind { real_target: t, unwind: Some(ref u) }
440+
| InlineAsm { destination: Some(t), cleanup: Some(ref u), .. } => {
441+
Some(t).into_iter().chain(slice::from_ref(u).into_iter().copied())
444442
}
443+
SwitchInt { ref targets, .. } => {
444+
None.into_iter().chain(targets.targets.iter().copied())
445+
}
446+
FalseEdge { real_target, ref imaginary_target } => Some(real_target)
447+
.into_iter()
448+
.chain(slice::from_ref(imaginary_target).into_iter().copied()),
445449
}
446450
}
447451

0 commit comments

Comments
 (0)