diff options
| author | SparrowLii <liyuan179@huawei.com> | 2022-05-17 08:41:01 +0800 |
|---|---|---|
| committer | SparrowLii <liyuan179@huawei.com> | 2022-05-17 08:41:01 +0800 |
| commit | 38bf1158bd850c80de42599c28602ae11727a133 (patch) | |
| tree | a125d76abf6c8a63bb7060c0f1e200a8264b0c6f /compiler/rustc_middle/src | |
| parent | 56d540e0571ac1b0633ce10644224c495aaf42a0 (diff) | |
| download | rust-38bf1158bd850c80de42599c28602ae11727a133.tar.gz rust-38bf1158bd850c80de42599c28602ae11727a133.zip | |
Change `Successors` to `impl Iterator<Item = BasicBlock>`
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/mir/generic_graph.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/mod.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/patch.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/predecessors.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/terminator.rs | 50 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/traversal.rs | 2 |
6 files changed, 34 insertions, 35 deletions
diff --git a/compiler/rustc_middle/src/mir/generic_graph.rs b/compiler/rustc_middle/src/mir/generic_graph.rs index dbebed67c2b..a4d78911b27 100644 --- a/compiler/rustc_middle/src/mir/generic_graph.rs +++ b/compiler/rustc_middle/src/mir/generic_graph.rs @@ -24,7 +24,7 @@ pub fn mir_fn_to_generic_graph<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'_>) -> Grap let terminator = body[source].terminator(); let labels = terminator.kind.fmt_successor_labels(); - for (&target, label) in terminator.successors().zip(labels) { + for (target, label) in terminator.successors().zip(labels) { let src = node(def_id, source); let trg = node(def_id, target); edges.push(Edge::new(src, trg, label.to_string())); diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index af18adac2ff..7a80afa7232 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1355,10 +1355,7 @@ pub enum InlineAsmOperand<'tcx> { /// Type for MIR `Assert` terminator error messages. pub type AssertMessage<'tcx> = AssertKind<Operand<'tcx>>; -// FIXME: Change `Successors` to `impl Iterator<Item = BasicBlock>`. -#[allow(rustc::pass_by_value)] -pub type Successors<'a> = - iter::Chain<option::IntoIter<&'a BasicBlock>, slice::Iter<'a, BasicBlock>>; +pub type Successors<'a> = impl Iterator<Item = BasicBlock> + 'a; pub type SuccessorsMut<'a> = iter::Chain<option::IntoIter<&'a mut BasicBlock>, slice::IterMut<'a, BasicBlock>>; @@ -3434,13 +3431,13 @@ impl<'tcx> graph::WithStartNode for Body<'tcx> { impl<'tcx> graph::WithSuccessors for Body<'tcx> { #[inline] fn successors(&self, node: Self::Node) -> <Self as GraphSuccessors<'_>>::Iter { - self.basic_blocks[node].terminator().successors().cloned() + self.basic_blocks[node].terminator().successors() } } impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> { type Item = BasicBlock; - type Iter = iter::Cloned<Successors<'b>>; + type Iter = Successors<'b>; } impl<'tcx, 'graph> graph::GraphPredecessors<'graph> for Body<'tcx> { diff --git a/compiler/rustc_middle/src/mir/patch.rs b/compiler/rustc_middle/src/mir/patch.rs index d03f9235efd..3bcb8f9c34c 100644 --- a/compiler/rustc_middle/src/mir/patch.rs +++ b/compiler/rustc_middle/src/mir/patch.rs @@ -166,9 +166,7 @@ impl<'tcx> MirPatch<'tcx> { // get terminator's targets and apply the statement to all of them. if loc.statement_index > body[loc.block].statements.len() { let term = body[loc.block].terminator(); - let successors = term.successors().clone(); - - for i in successors { + for i in term.successors() { stmts_and_targets .push((Statement { source_info, kind: stmt.clone() }, i.clone())); } diff --git a/compiler/rustc_middle/src/mir/predecessors.rs b/compiler/rustc_middle/src/mir/predecessors.rs index 4fe2cde7532..ad09328585d 100644 --- a/compiler/rustc_middle/src/mir/predecessors.rs +++ b/compiler/rustc_middle/src/mir/predecessors.rs @@ -43,7 +43,7 @@ impl PredecessorCache { let mut preds = IndexVec::from_elem(SmallVec::new(), basic_blocks); for (bb, data) in basic_blocks.iter_enumerated() { if let Some(term) = &data.terminator { - for &succ in term.successors() { + for succ in term.successors() { preds[succ].push(bb); } } diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index e6eb63fd3b2..fb3856b4952 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -416,32 +416,36 @@ impl<'tcx> TerminatorKind<'tcx> { | Return | Unreachable | Call { destination: None, cleanup: None, .. } - | InlineAsm { destination: None, cleanup: None, .. } => None.into_iter().chain(&[]), - Goto { target: ref t } - | Call { destination: None, cleanup: Some(ref t), .. } - | Call { destination: Some((_, ref t)), cleanup: None, .. } - | Yield { resume: ref t, drop: None, .. } - | DropAndReplace { target: ref t, unwind: None, .. } - | Drop { target: ref t, unwind: None, .. } - | Assert { target: ref t, cleanup: None, .. } - | FalseUnwind { real_target: ref t, unwind: None } - | InlineAsm { destination: Some(ref t), cleanup: None, .. } - | InlineAsm { destination: None, cleanup: Some(ref t), .. } => { - Some(t).into_iter().chain(&[]) + | InlineAsm { destination: None, cleanup: None, .. } => { + None.into_iter().chain((&[]).into_iter().copied()) } - Call { destination: Some((_, ref t)), cleanup: Some(ref u), .. } - | Yield { resume: ref t, drop: Some(ref u), .. } - | DropAndReplace { target: ref t, unwind: Some(ref u), .. } - | Drop { target: ref t, unwind: Some(ref u), .. } - | Assert { target: ref t, cleanup: Some(ref u), .. } - | FalseUnwind { real_target: ref t, unwind: Some(ref u) } - | InlineAsm { destination: Some(ref t), cleanup: Some(ref u), .. } => { - Some(t).into_iter().chain(slice::from_ref(u)) + Goto { target: t } + | Call { destination: None, cleanup: Some(t), .. } + | Call { destination: Some((_, t)), cleanup: None, .. } + | Yield { resume: t, drop: None, .. } + | DropAndReplace { target: t, unwind: None, .. } + | Drop { target: t, unwind: None, .. } + | Assert { target: t, cleanup: None, .. } + | FalseUnwind { real_target: t, unwind: None } + | InlineAsm { destination: Some(t), cleanup: None, .. } + | InlineAsm { destination: None, cleanup: Some(t), .. } => { + Some(t).into_iter().chain((&[]).into_iter().copied()) } - SwitchInt { ref targets, .. } => None.into_iter().chain(&targets.targets), - FalseEdge { ref real_target, ref imaginary_target } => { - Some(real_target).into_iter().chain(slice::from_ref(imaginary_target)) + Call { destination: Some((_, t)), cleanup: Some(ref u), .. } + | Yield { resume: t, drop: Some(ref u), .. } + | DropAndReplace { target: t, unwind: Some(ref u), .. } + | Drop { target: t, unwind: Some(ref u), .. } + | Assert { target: t, cleanup: Some(ref u), .. } + | FalseUnwind { real_target: t, unwind: Some(ref u) } + | InlineAsm { destination: Some(t), cleanup: Some(ref u), .. } => { + Some(t).into_iter().chain(slice::from_ref(u).into_iter().copied()) } + SwitchInt { ref targets, .. } => { + None.into_iter().chain(targets.targets.iter().copied()) + } + FalseEdge { real_target, ref imaginary_target } => Some(real_target) + .into_iter() + .chain(slice::from_ref(imaginary_target).into_iter().copied()), } } diff --git a/compiler/rustc_middle/src/mir/traversal.rs b/compiler/rustc_middle/src/mir/traversal.rs index 8d831cc73b8..1cbfed62156 100644 --- a/compiler/rustc_middle/src/mir/traversal.rs +++ b/compiler/rustc_middle/src/mir/traversal.rs @@ -180,7 +180,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> { // two iterations yield `C` and finally `A` for a final traversal of [E, D, B, C, A] loop { let bb = if let Some(&mut (_, ref mut iter)) = self.visit_stack.last_mut() { - if let Some(&bb) = iter.next() { + if let Some(bb) = iter.next() { bb } else { break; |
