diff options
| author | pierwill <pierwill@users.noreply.github.com> | 2021-12-07 12:29:13 -0600 |
|---|---|---|
| committer | pierwill <pierwill@users.noreply.github.com> | 2021-12-22 10:50:57 -0600 |
| commit | e6ff0bac1ec1271439ed6a7dd35f861e293cd025 (patch) | |
| tree | a1e830ecf30670c468484cea557b4ed79d12f5f8 /compiler/rustc_data_structures/src/graph/vec_graph | |
| parent | a4a8c241c7bcce3604a0ce130a65084101d0ab47 (diff) | |
| download | rust-e6ff0bac1ec1271439ed6a7dd35f861e293cd025.tar.gz rust-e6ff0bac1ec1271439ed6a7dd35f861e293cd025.zip | |
rustc `VecGraph`: require the index type to implement Ord
Diffstat (limited to 'compiler/rustc_data_structures/src/graph/vec_graph')
| -rw-r--r-- | compiler/rustc_data_structures/src/graph/vec_graph/mod.rs | 8 |
1 files changed, 5 insertions, 3 deletions
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 826d0fe9ab4..3d91bcade59 100644 --- a/compiler/rustc_data_structures/src/graph/vec_graph/mod.rs +++ b/compiler/rustc_data_structures/src/graph/vec_graph/mod.rs @@ -1,3 +1,5 @@ +use std::cmp::Ord; + use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors}; use rustc_index::vec::{Idx, IndexVec}; @@ -17,10 +19,10 @@ pub struct VecGraph<N: Idx> { edge_targets: Vec<N>, } -impl<N: Idx> VecGraph<N> { +impl<N: Idx + Ord> VecGraph<N> { pub fn new(num_nodes: usize, mut edge_pairs: Vec<(N, N)>) -> Self { // Sort the edges by the source -- this is important. - edge_pairs.sort_by_key(|&edge_pairs| (edge_pairs.0.index(), edge_pairs.1.index())); + edge_pairs.sort(); let num_edges = edge_pairs.len(); @@ -100,7 +102,7 @@ impl<'graph, N: Idx> GraphSuccessors<'graph> for VecGraph<N> { type Iter = std::iter::Cloned<std::slice::Iter<'graph, N>>; } -impl<N: Idx> WithSuccessors for VecGraph<N> { +impl<N: Idx + Ord> WithSuccessors for VecGraph<N> { fn successors(&self, node: N) -> <Self as GraphSuccessors<'_>>::Iter { self.successors(node).iter().cloned() } |
