Skip to content

Commit f1c588f

Browse files
committed
use fold instead of try_fold now that .by_ref().next() has been inlined
1 parent a398b6b commit f1c588f

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

library/core/src/array/iter.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,12 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> {
135135
Fold: FnMut(Acc, Self::Item) -> Acc,
136136
{
137137
let data = &mut self.data;
138-
// FIXME: This uses try_fold(&mut iter) instead of fold(iter) because the latter
139-
// would go through the blanket `impl Iterator for &mut I` implementation
140-
// which lacks inline annotations on its methods and adding those would be a larger
141-
// perturbation than using try_fold here.
142-
// Whether it would be beneficial to add those annotations should be investigated separately.
143-
(&mut self.alive)
144-
.try_fold::<_, _, Result<_, !>>(init, |acc, idx| {
145-
// SAFETY: idx is obtained by folding over the `alive` range, which implies the
146-
// value is currently considered alive but as the range is being consumed each value
147-
// we read here will only be read once and then considered dead.
148-
Ok(fold(acc, unsafe { data.get_unchecked(idx).assume_init_read() }))
149-
})
150-
.unwrap()
138+
self.alive.by_ref().fold(init, |acc, idx| {
139+
// SAFETY: idx is obtained by folding over the `alive` range, which implies the
140+
// value is currently considered alive but as the range is being consumed each value
141+
// we read here will only be read once and then considered dead.
142+
fold(acc, unsafe { data.get_unchecked(idx).assume_init_read() })
143+
})
151144
}
152145

153146
fn count(self) -> usize {

0 commit comments

Comments
 (0)