From 435db9b9bd404c1bc632fbb6ade8b4ce92c2828c Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 15 Apr 2024 13:33:08 +0000 Subject: Use RPITIT for `Successors` and `Predecessors` traits Now with RPITIT instead of GAT! --- compiler/rustc_data_structures/src/graph/mod.rs | 12 ++---------- compiler/rustc_data_structures/src/graph/reference.rs | 8 ++------ compiler/rustc_data_structures/src/graph/scc/mod.rs | 4 +--- compiler/rustc_data_structures/src/graph/tests.rs | 10 ++-------- compiler/rustc_data_structures/src/graph/vec_graph/mod.rs | 4 +--- 5 files changed, 8 insertions(+), 30 deletions(-) (limited to 'compiler/rustc_data_structures/src/graph') diff --git a/compiler/rustc_data_structures/src/graph/mod.rs b/compiler/rustc_data_structures/src/graph/mod.rs index 61bee2ee0bb..3ae3023a91b 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 16b019374be..7a487552f53 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 1cd0edfe57f..5021e5e8fc0 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 118b6bd3eb6..85c2703cc25 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 3f9d8ec0aca..26c86469fad 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() } } -- cgit 1.4.1-3-g733a5