about summary refs log tree commit diff
path: root/library/core/src/array
diff options
context:
space:
mode:
authorThe 8472 <git@infinite-source.de>2023-03-13 20:07:53 +0100
committerThe 8472 <git@infinite-source.de>2023-03-27 16:03:14 +0200
commite29b27b4a4c6b6fc80e38d2747c8076a59475c03 (patch)
tree8b39f203c9919d8f90a084ee8e5d80167b33e92e /library/core/src/array
parent69db91b8b25de51633ac9f089cd7fb10a58c2b2a (diff)
downloadrust-e29b27b4a4c6b6fc80e38d2747c8076a59475c03.tar.gz
rust-e29b27b4a4c6b6fc80e38d2747c8076a59475c03.zip
replace advance_by returning usize with Result<(), NonZeroUsize>
Diffstat (limited to 'library/core/src/array')
-rw-r--r--library/core/src/array/iter.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs
index 2d853dd6684..73e2c2cfbbe 100644
--- a/library/core/src/array/iter.rs
+++ b/library/core/src/array/iter.rs
@@ -1,5 +1,6 @@
 //! Defines the `IntoIter` owned iterator for arrays.
 
+use crate::num::NonZeroUsize;
 use crate::{
     fmt,
     iter::{self, ExactSizeIterator, FusedIterator, TrustedLen},
@@ -284,7 +285,7 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> {
         self.next_back()
     }
 
-    fn advance_by(&mut self, n: usize) -> usize {
+    fn advance_by(&mut self, n: usize) -> Result<(), NonZeroUsize> {
         // This also moves the start, which marks them as conceptually "dropped",
         // so if anything goes bad then our drop impl won't double-free them.
         let range_to_drop = self.alive.take_prefix(n);
@@ -296,7 +297,7 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> {
             ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(slice));
         }
 
-        remaining
+        NonZeroUsize::new(remaining).map_or(Ok(()), Err)
     }
 }
 
@@ -333,7 +334,7 @@ impl<T, const N: usize> DoubleEndedIterator for IntoIter<T, N> {
         })
     }
 
-    fn advance_back_by(&mut self, n: usize) -> usize {
+    fn advance_back_by(&mut self, n: usize) -> Result<(), NonZeroUsize> {
         // This also moves the end, which marks them as conceptually "dropped",
         // so if anything goes bad then our drop impl won't double-free them.
         let range_to_drop = self.alive.take_suffix(n);
@@ -345,7 +346,7 @@ impl<T, const N: usize> DoubleEndedIterator for IntoIter<T, N> {
             ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(slice));
         }
 
-        remaining
+        NonZeroUsize::new(remaining).map_or(Ok(()), Err)
     }
 }