diff --git a/compiler/rustc_borrowck/src/constraints/graph.rs b/compiler/rustc_borrowck/src/constraints/graph.rs index 2dfaeb3ae7605..540b466560c5d 100644 --- a/compiler/rustc_borrowck/src/constraints/graph.rs +++ b/compiler/rustc_borrowck/src/constraints/graph.rs @@ -223,9 +223,7 @@ impl<'s, 'tcx, D: ConstraintGraphDirection> graph::DirectedGraph for RegionGraph } 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 61bee2ee0bba5..3ae3023a91b34 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 16b019374be7f..7a487552f5385 100644 --- a/compiler/rustc_data_structures/src/graph/reference.rs +++ b/compiler/rustc_data_structures/src/graph/reference.rs @@ -15,17 +15,13 @@ impl<'graph, G: StartNode> StartNode for &'graph G { } 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 1cd0edfe57fd4..5021e5e8fc090 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 @@ impl NumEdges for Sccs { } 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 118b6bd3eb687..85c2703cc2538 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 @@ impl StartNode for TestGraph { } 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 3f9d8ec0acabb..26c86469fad84 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 @@ impl NumEdges for VecGraph { } 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 36e067c130641..1086d647721b7 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 @@ impl<'tcx> graph::StartNode for BasicBlocks<'tcx> { } 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 c187466403f83..1895735ab3523 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -209,19 +209,15 @@ impl graph::StartNode for CoverageGraph { } 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() } }