diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2024-04-14 15:40:26 +0000 | 
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2024-04-14 15:48:53 +0000 | 
| commit | 0d5fc9bf584f0e8700f0c3d2854bb6c70453f624 (patch) | |
| tree | 163982785183644158a7d71d90407fa85e9a41a1 /compiler/rustc_data_structures/src/graph/mod.rs | |
| parent | 398da593a53161c1ef9ca7dabbc5e9edf67deac6 (diff) | |
| download | rust-0d5fc9bf584f0e8700f0c3d2854bb6c70453f624.tar.gz rust-0d5fc9bf584f0e8700f0c3d2854bb6c70453f624.zip | |
Merge `{With,Graph}{Successors,Predecessors}` into `{Successors,Predecessors}`
Now with GAT!
Diffstat (limited to 'compiler/rustc_data_structures/src/graph/mod.rs')
| -rw-r--r-- | compiler/rustc_data_structures/src/graph/mod.rs | 43 | 
1 files changed, 14 insertions, 29 deletions
| diff --git a/compiler/rustc_data_structures/src/graph/mod.rs b/compiler/rustc_data_structures/src/graph/mod.rs index 853b8f1775e..ef1dac1509e 100644 --- a/compiler/rustc_data_structures/src/graph/mod.rs +++ b/compiler/rustc_data_structures/src/graph/mod.rs @@ -20,55 +20,40 @@ pub trait WithNumEdges: DirectedGraph { fn num_edges(&self) -> usize; } -pub trait WithSuccessors: DirectedGraph -where - Self: for<'graph> GraphSuccessors<'graph, Item = <Self as DirectedGraph>::Node>, -{ - fn successors(&self, node: Self::Node) -> <Self as GraphSuccessors<'_>>::Iter; +pub trait Successors: DirectedGraph { + type Successors<'g>: Iterator<Item = Self::Node> + where + Self: 'g; + + fn successors(&self, node: Self::Node) -> Self::Successors<'_>; fn depth_first_search(&self, from: Self::Node) -> iterate::DepthFirstSearch<'_, Self> { iterate::DepthFirstSearch::new(self).with_start_node(from) } } -#[allow(unused_lifetimes)] -pub trait GraphSuccessors<'graph> { - type Item; - type Iter: Iterator<Item = Self::Item>; -} +pub trait Predecessors: DirectedGraph { + type Predecessors<'g>: Iterator<Item = Self::Node> + where + Self: 'g; -pub trait WithPredecessors: DirectedGraph -where - Self: for<'graph> GraphPredecessors<'graph, Item = <Self as DirectedGraph>::Node>, -{ - fn predecessors(&self, node: Self::Node) -> <Self as GraphPredecessors<'_>>::Iter; -} - -#[allow(unused_lifetimes)] -pub trait GraphPredecessors<'graph> { - type Item; - type Iter: Iterator<Item = Self::Item>; + fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_>; } pub trait WithStartNode: DirectedGraph { fn start_node(&self) -> Self::Node; } -pub trait ControlFlowGraph: - DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors -{ +pub trait ControlFlowGraph: DirectedGraph + WithStartNode + Predecessors + Successors { // convenient trait } -impl<T> ControlFlowGraph for T where - T: DirectedGraph + WithStartNode + WithPredecessors + WithSuccessors -{ -} +impl<T> ControlFlowGraph for T where T: DirectedGraph + WithStartNode + Predecessors + Successors {} /// Returns `true` if the graph has a cycle that is reachable from the start node. pub fn is_cyclic<G>(graph: &G) -> bool where - G: ?Sized + DirectedGraph + WithStartNode + WithSuccessors, + G: ?Sized + DirectedGraph + WithStartNode + Successors, { iterate::TriColorDepthFirstSearch::new(graph) .run_from_start(&mut iterate::CycleDetector) | 
