From 696a7a1f04ce7969a80ea5be45195d32d705ed72 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 25 Feb 2026 08:09:43 -0800 Subject: [PATCH] Simplify `AppendOnlyVec` iterators --- compiler/rustc_data_structures/src/sync/vec.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_data_structures/src/sync/vec.rs b/compiler/rustc_data_structures/src/sync/vec.rs index afbb0cef9f956..d35e2c61f1e19 100644 --- a/compiler/rustc_data_structures/src/sync/vec.rs +++ b/compiler/rustc_data_structures/src/sync/vec.rs @@ -46,20 +46,17 @@ impl AppendOnlyVec { } pub fn iter_enumerated(&self) -> impl Iterator { - (0..) - .map(|i| (i, self.get(i))) - .take_while(|(_, o)| o.is_some()) - .filter_map(|(i, o)| Some((i, o?))) + (0..).map_while(|i| Some((i, self.get(i)?))) } pub fn iter(&self) -> impl Iterator { - (0..).map(|i| self.get(i)).take_while(|o| o.is_some()).flatten() + (0..).map_while(|i| self.get(i)) } } impl AppendOnlyVec { pub fn contains(&self, val: T) -> bool { - self.iter_enumerated().any(|(_, v)| v == val) + self.iter().any(|v| v == val) } }