From 2276c5e3d76591561e28fed760984e75c46bc407 Mon Sep 17 00:00:00 2001 From: The8472 Date: Tue, 27 Jul 2021 00:14:19 +0200 Subject: [PATCH] from review: add a comment why try_fold was chosen instead of fold --- library/core/src/array/iter.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 004d1736b0f3..f6616399610a 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -129,6 +129,11 @@ impl Iterator for IntoIter { Fold: FnMut(Acc, Self::Item) -> Acc, { let data = &mut self.data; + // FIXME: This uses try_fold(&mut iter) instead of fold(iter) because the latter + // would go through the blanket `impl Iterator for &mut I` implementation + // which lacks inline annotations on its methods and adding those would be a larger + // perturbation than using try_fold here. + // Whether it would be beneficial to add those annotations should be investigated separately. (&mut self.alive) .try_fold::<_, _, Result<_, !>>(init, |acc, idx| { // SAFETY: idx is obtained by folding over the `alive` range, which implies the