about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThe8472 <git@infinite-source.de>2021-07-27 00:14:19 +0200
committerThe8472 <git@infinite-source.de>2021-07-27 00:14:19 +0200
commit2276c5e3d76591561e28fed760984e75c46bc407 (patch)
tree4725a1a7b9c0f5d172a2f43acdaed24d9746e4f9
parente015e9da717bf501ab4752b2ea045d899f804a42 (diff)
downloadrust-2276c5e3d76591561e28fed760984e75c46bc407.tar.gz
rust-2276c5e3d76591561e28fed760984e75c46bc407.zip
from review: add a comment why try_fold was chosen instead of fold
-rw-r--r--library/core/src/array/iter.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs
index 004d1736b0f..f6616399610 100644
--- a/library/core/src/array/iter.rs
+++ b/library/core/src/array/iter.rs
@@ -129,6 +129,11 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> {
         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