Skip to content

Commit b15d42a

Browse files
committed
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.
1 parent 9363200 commit b15d42a

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

compiler/rustc_data_structures/src/graph/iterate/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,21 @@ pub fn reverse_post_order<G: DirectedGraph + Successors>(
7070
}
7171

7272
/// A "depth-first search" iterator for a directed graph.
73-
pub struct DepthFirstSearch<'graph, G>
73+
pub struct DepthFirstSearch<G>
7474
where
75-
G: ?Sized + DirectedGraph + Successors,
75+
G: DirectedGraph + Successors,
7676
{
77-
graph: &'graph G,
77+
graph: G,
7878
stack: Vec<G::Node>,
7979
visited: BitSet<G::Node>,
8080
}
8181

82-
impl<'graph, G> DepthFirstSearch<'graph, G>
82+
impl<G> DepthFirstSearch<G>
8383
where
84-
G: ?Sized + DirectedGraph + Successors,
84+
G: DirectedGraph + Successors,
8585
{
86-
pub fn new(graph: &'graph G) -> Self {
87-
Self { graph, stack: vec![], visited: BitSet::new_empty(graph.num_nodes()) }
86+
pub fn new(graph: G) -> Self {
87+
Self { stack: vec![], visited: BitSet::new_empty(graph.num_nodes()), graph }
8888
}
8989

9090
/// Version of `push_start_node` that is convenient for chained
@@ -125,9 +125,9 @@ where
125125
}
126126
}
127127

128-
impl<G> std::fmt::Debug for DepthFirstSearch<'_, G>
128+
impl<G> std::fmt::Debug for DepthFirstSearch<G>
129129
where
130-
G: ?Sized + DirectedGraph + Successors,
130+
G: DirectedGraph + Successors,
131131
{
132132
fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
133133
let mut f = fmt.debug_set();
@@ -138,9 +138,9 @@ where
138138
}
139139
}
140140

141-
impl<G> Iterator for DepthFirstSearch<'_, G>
141+
impl<G> Iterator for DepthFirstSearch<G>
142142
where
143-
G: ?Sized + DirectedGraph + Successors,
143+
G: DirectedGraph + Successors,
144144
{
145145
type Item = G::Node;
146146

compiler/rustc_data_structures/src/graph/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ where
4646
.is_some()
4747
}
4848

49-
pub fn depth_first_search<G>(graph: &G, from: G::Node) -> iterate::DepthFirstSearch<'_, G>
49+
pub fn depth_first_search<G>(graph: G, from: G::Node) -> iterate::DepthFirstSearch<G>
5050
where
51-
G: ?Sized + Successors,
51+
G: Successors,
5252
{
5353
iterate::DepthFirstSearch::new(graph).with_start_node(from)
5454
}

0 commit comments

Comments
 (0)