diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2024-04-15 18:17:51 +0000 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2024-04-15 23:20:52 +0000 |
| commit | 7d2cb3dda732028c7f8dfa8de5876da5be4bad9d (patch) | |
| tree | ab76f947458382e1174ed1f53b5562edb3920552 /compiler/rustc_data_structures/src/graph | |
| parent | 86a576528c003992c7a4ba9dd0601ad637340efb (diff) | |
| download | rust-7d2cb3dda732028c7f8dfa8de5876da5be4bad9d.tar.gz rust-7d2cb3dda732028c7f8dfa8de5876da5be4bad9d.zip | |
Make `graph::DepthFirstSearch` accept `G` by value
It's required for the next commit. Note that you can still have `G = &H`, since there are implementations of all the graph traits for references.
Diffstat (limited to 'compiler/rustc_data_structures/src/graph')
| -rw-r--r-- | compiler/rustc_data_structures/src/graph/iterate/mod.rs | 22 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/graph/mod.rs | 4 |
2 files changed, 13 insertions, 13 deletions
diff --git a/compiler/rustc_data_structures/src/graph/iterate/mod.rs b/compiler/rustc_data_structures/src/graph/iterate/mod.rs index 7a77f2c0dbb..78d05a6e195 100644 --- a/compiler/rustc_data_structures/src/graph/iterate/mod.rs +++ b/compiler/rustc_data_structures/src/graph/iterate/mod.rs @@ -70,21 +70,21 @@ pub fn reverse_post_order<G: DirectedGraph + Successors>( } /// A "depth-first search" iterator for a directed graph. -pub struct DepthFirstSearch<'graph, G> +pub struct DepthFirstSearch<G> where - G: ?Sized + DirectedGraph + Successors, + G: DirectedGraph + Successors, { - graph: &'graph G, + graph: G, stack: Vec<G::Node>, visited: BitSet<G::Node>, } -impl<'graph, G> DepthFirstSearch<'graph, G> +impl<G> DepthFirstSearch<G> where - G: ?Sized + DirectedGraph + Successors, + G: DirectedGraph + Successors, { - pub fn new(graph: &'graph G) -> Self { - Self { graph, stack: vec![], visited: BitSet::new_empty(graph.num_nodes()) } + pub fn new(graph: G) -> Self { + Self { stack: vec![], visited: BitSet::new_empty(graph.num_nodes()), graph } } /// Version of `push_start_node` that is convenient for chained @@ -125,9 +125,9 @@ where } } -impl<G> std::fmt::Debug for DepthFirstSearch<'_, G> +impl<G> std::fmt::Debug for DepthFirstSearch<G> where - G: ?Sized + DirectedGraph + Successors, + G: DirectedGraph + Successors, { fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut f = fmt.debug_set(); @@ -138,9 +138,9 @@ where } } -impl<G> Iterator for DepthFirstSearch<'_, G> +impl<G> Iterator for DepthFirstSearch<G> where - G: ?Sized + DirectedGraph + Successors, + G: DirectedGraph + Successors, { type Item = G::Node; diff --git a/compiler/rustc_data_structures/src/graph/mod.rs b/compiler/rustc_data_structures/src/graph/mod.rs index 3ae3023a91b..0906c04716b 100644 --- a/compiler/rustc_data_structures/src/graph/mod.rs +++ b/compiler/rustc_data_structures/src/graph/mod.rs @@ -46,9 +46,9 @@ where .is_some() } -pub fn depth_first_search<G>(graph: &G, from: G::Node) -> iterate::DepthFirstSearch<'_, G> +pub fn depth_first_search<G>(graph: G, from: G::Node) -> iterate::DepthFirstSearch<G> where - G: ?Sized + Successors, + G: Successors, { iterate::DepthFirstSearch::new(graph).with_start_node(from) } |
