diff --git a/compiler/rustc_borrowck/src/constraints/graph.rs b/compiler/rustc_borrowck/src/constraints/graph.rs index 2dfaeb3ae76..540b466560c 100644 --- a/compiler/rustc_borrowck/src/constraints/graph.rs +++ b/compiler/rustc_borrowck/src/constraints/graph.rs @@ -223,9 +223,7 @@ fn num_nodes(&self) -> usize { } impl<'s, 'tcx, D: ConstraintGraphDirection> graph::Successors for RegionGraph<'s, 'tcx, D> { - type Successors<'g> = Successors<'s, 'tcx, D> where Self: 'g; - - fn successors(&self, node: Self::Node) -> Self::Successors<'_> { + fn successors(&self, node: Self::Node) -> impl Iterator { self.outgoing_regions(node) } } diff --git a/compiler/rustc_data_structures/src/graph/mod.rs b/compiler/rustc_data_structures/src/graph/mod.rs index 61bee2ee0bb..3ae3023a91b 100644 --- a/compiler/rustc_data_structures/src/graph/mod.rs +++ b/compiler/rustc_data_structures/src/graph/mod.rs @@ -25,19 +25,11 @@ pub trait StartNode: DirectedGraph { } pub trait Successors: DirectedGraph { - type Successors<'g>: Iterator - where - Self: 'g; - - fn successors(&self, node: Self::Node) -> Self::Successors<'_>; + fn successors(&self, node: Self::Node) -> impl Iterator; } pub trait Predecessors: DirectedGraph { - type Predecessors<'g>: Iterator - where - Self: 'g; - - fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_>; + fn predecessors(&self, node: Self::Node) -> impl Iterator; } /// Alias for [`DirectedGraph`] + [`StartNode`] + [`Predecessors`] + [`Successors`]. diff --git a/compiler/rustc_data_structures/src/graph/reference.rs b/compiler/rustc_data_structures/src/graph/reference.rs index 16b019374be..7a487552f53 100644 --- a/compiler/rustc_data_structures/src/graph/reference.rs +++ b/compiler/rustc_data_structures/src/graph/reference.rs @@ -15,17 +15,13 @@ fn start_node(&self) -> Self::Node { } impl<'graph, G: Successors> Successors for &'graph G { - type Successors<'g> = G::Successors<'g> where 'graph: 'g; - - fn successors(&self, node: Self::Node) -> Self::Successors<'_> { + fn successors(&self, node: Self::Node) -> impl Iterator { (**self).successors(node) } } impl<'graph, G: Predecessors> Predecessors for &'graph G { - type Predecessors<'g> = G::Predecessors<'g> where 'graph: 'g; - - fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_> { + fn predecessors(&self, node: Self::Node) -> impl Iterator { (**self).predecessors(node) } } diff --git a/compiler/rustc_data_structures/src/graph/scc/mod.rs b/compiler/rustc_data_structures/src/graph/scc/mod.rs index 1cd0edfe57f..5021e5e8fc0 100644 --- a/compiler/rustc_data_structures/src/graph/scc/mod.rs +++ b/compiler/rustc_data_structures/src/graph/scc/mod.rs @@ -104,9 +104,7 @@ fn num_edges(&self) -> usize { } impl Successors for Sccs { - type Successors<'g> = std::iter::Cloned>; - - fn successors(&self, node: S) -> Self::Successors<'_> { + fn successors(&self, node: S) -> impl Iterator { self.successors(node).iter().cloned() } } diff --git a/compiler/rustc_data_structures/src/graph/tests.rs b/compiler/rustc_data_structures/src/graph/tests.rs index 118b6bd3eb6..85c2703cc25 100644 --- a/compiler/rustc_data_structures/src/graph/tests.rs +++ b/compiler/rustc_data_structures/src/graph/tests.rs @@ -1,7 +1,5 @@ use crate::fx::FxHashMap; use std::cmp::max; -use std::iter; -use std::slice; use super::*; @@ -49,17 +47,13 @@ fn start_node(&self) -> usize { } impl Predecessors for TestGraph { - type Predecessors<'g> = iter::Cloned>; - - fn predecessors(&self, node: usize) -> Self::Predecessors<'_> { + fn predecessors(&self, node: usize) -> impl Iterator { self.predecessors[&node].iter().cloned() } } impl Successors for TestGraph { - type Successors<'g> = iter::Cloned>; - - fn successors(&self, node: usize) -> Self::Successors<'_> { + fn successors(&self, node: usize) -> impl Iterator { self.successors[&node].iter().cloned() } } diff --git a/compiler/rustc_data_structures/src/graph/vec_graph/mod.rs b/compiler/rustc_data_structures/src/graph/vec_graph/mod.rs index 3f9d8ec0aca..26c86469fad 100644 --- a/compiler/rustc_data_structures/src/graph/vec_graph/mod.rs +++ b/compiler/rustc_data_structures/src/graph/vec_graph/mod.rs @@ -93,9 +93,7 @@ fn num_edges(&self) -> usize { } impl Successors for VecGraph { - type Successors<'g> = std::iter::Cloned>; - - fn successors(&self, node: N) -> Self::Successors<'_> { + fn successors(&self, node: N) -> impl Iterator { self.successors(node).iter().cloned() } } diff --git a/compiler/rustc_middle/src/mir/basic_blocks.rs b/compiler/rustc_middle/src/mir/basic_blocks.rs index 36e067c1306..1086d647721 100644 --- a/compiler/rustc_middle/src/mir/basic_blocks.rs +++ b/compiler/rustc_middle/src/mir/basic_blocks.rs @@ -1,5 +1,5 @@ use crate::mir::traversal::Postorder; -use crate::mir::{BasicBlock, BasicBlockData, Successors, Terminator, TerminatorKind, START_BLOCK}; +use crate::mir::{BasicBlock, BasicBlockData, Terminator, TerminatorKind, START_BLOCK}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::graph; @@ -156,19 +156,15 @@ fn start_node(&self) -> Self::Node { } impl<'tcx> graph::Successors for BasicBlocks<'tcx> { - type Successors<'b> = Successors<'b> where 'tcx: 'b; - #[inline] - fn successors(&self, node: Self::Node) -> Self::Successors<'_> { + fn successors(&self, node: Self::Node) -> impl Iterator { self.basic_blocks[node].terminator().successors() } } impl<'tcx> graph::Predecessors for BasicBlocks<'tcx> { - type Predecessors<'b> = std::iter::Copied> where 'tcx: 'b; - #[inline] - fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_> { + fn predecessors(&self, node: Self::Node) -> impl Iterator { self.predecessors()[node].iter().copied() } } diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs index c187466403f..1895735ab35 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -209,19 +209,15 @@ fn start_node(&self) -> Self::Node { } impl graph::Successors for CoverageGraph { - type Successors<'g> = std::iter::Cloned>; - #[inline] - fn successors(&self, node: Self::Node) -> Self::Successors<'_> { + fn successors(&self, node: Self::Node) -> impl Iterator { self.successors[node].iter().cloned() } } impl graph::Predecessors for CoverageGraph { - type Predecessors<'g> = std::iter::Copied>; - #[inline] - fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_> { + fn predecessors(&self, node: Self::Node) -> impl Iterator { self.predecessors[node].iter().copied() } }