diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-05-07 09:35:50 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-05-09 08:13:24 +1000 |
| commit | d3d01e1cd3a4157692e136f3a1f8e0a5e37f3e36 (patch) | |
| tree | e8b2ee9299741a165d8da729a6086e2cd3ad9604 /compiler/rustc_data_structures | |
| parent | f5d7d346a48b75ef566674fca05cd4b29a985678 (diff) | |
| download | rust-d3d01e1cd3a4157692e136f3a1f8e0a5e37f3e36.tar.gz rust-d3d01e1cd3a4157692e136f3a1f8e0a5e37f3e36.zip | |
Remove `vec_linked_list`.
It provides a way to effectively embed a linked list within an `IndexVec` and also iterate over that list. It's written in a very generic way, involving two traits `Links` and `LinkElem`. But the `Links` trait is only impl'd for `IndexVec` and `&IndexVec`, and the whole thing is only used in one module within `rustc_borrowck`. So I think it's over-engineered and hard to read. Plus it has no comments. This commit removes it, and adds a (non-generic) local iterator for the use within `rustc_borrowck`. Much simpler.
Diffstat (limited to 'compiler/rustc_data_structures')
| -rw-r--r-- | compiler/rustc_data_structures/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_data_structures/src/vec_linked_list.rs | 70 |
2 files changed, 0 insertions, 71 deletions
diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 2e5f3806b12..407ee0453e5 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -85,7 +85,6 @@ pub mod temp_dir; pub mod transitive_relation; pub mod unhash; pub mod unord; -pub mod vec_linked_list; pub mod work_queue; mod atomic_ref; diff --git a/compiler/rustc_data_structures/src/vec_linked_list.rs b/compiler/rustc_data_structures/src/vec_linked_list.rs deleted file mode 100644 index fda72c9a3b2..00000000000 --- a/compiler/rustc_data_structures/src/vec_linked_list.rs +++ /dev/null @@ -1,70 +0,0 @@ -use rustc_index::{Idx, IndexVec}; - -pub fn iter<Ls>( - first: Option<Ls::LinkIndex>, - links: &Ls, -) -> impl Iterator<Item = Ls::LinkIndex> + '_ -where - Ls: Links, -{ - VecLinkedListIterator { links, current: first } -} - -pub struct VecLinkedListIterator<Ls> -where - Ls: Links, -{ - links: Ls, - current: Option<Ls::LinkIndex>, -} - -impl<Ls> Iterator for VecLinkedListIterator<Ls> -where - Ls: Links, -{ - type Item = Ls::LinkIndex; - - fn next(&mut self) -> Option<Ls::LinkIndex> { - if let Some(c) = self.current { - self.current = <Ls as Links>::next(&self.links, c); - Some(c) - } else { - None - } - } -} - -pub trait Links { - type LinkIndex: Copy; - - fn next(links: &Self, index: Self::LinkIndex) -> Option<Self::LinkIndex>; -} - -impl<Ls> Links for &Ls -where - Ls: Links, -{ - type LinkIndex = Ls::LinkIndex; - - fn next(links: &Self, index: Ls::LinkIndex) -> Option<Ls::LinkIndex> { - <Ls as Links>::next(links, index) - } -} - -pub trait LinkElem { - type LinkIndex: Copy; - - fn next(elem: &Self) -> Option<Self::LinkIndex>; -} - -impl<L, E> Links for IndexVec<L, E> -where - E: LinkElem<LinkIndex = L>, - L: Idx, -{ - type LinkIndex = L; - - fn next(links: &Self, index: L) -> Option<L> { - <E as LinkElem>::next(&links[index]) - } -} |
