diff options
| author | bors <bors@rust-lang.org> | 2023-03-28 15:18:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-03-28 15:18:16 +0000 |
| commit | 478cbb42b730ba4739351b72ce2aa928e78e2f81 (patch) | |
| tree | bf25c6aa92d6d0ad61724051f4404c237df72d71 /library/core/src/array | |
| parent | bf57e8ada6dc62369d1cee7ab055fb4074bd2d10 (diff) | |
| parent | 60ce19d848682b10543934229750cf30ef7af8a6 (diff) | |
| download | rust-478cbb42b730ba4739351b72ce2aa928e78e2f81.tar.gz rust-478cbb42b730ba4739351b72ce2aa928e78e2f81.zip | |
Auto merge of #109692 - Nilstrieb:rollup-hq65rps, r=Nilstrieb
Rollup of 8 pull requests Successful merges: - #91793 (socket ancillary data implementation for FreeBSD (from 13 and above).) - #92284 (Change advance(_back)_by to return the remainder instead of the number of processed elements) - #102472 (stop special-casing `'static` in evaluation) - #108480 (Use Rayon's TLV directly) - #109321 (Erase impl regions when checking for impossible to eagerly monomorphize items) - #109470 (Correctly substitute GAT's type used in `normalize_param_env` in `check_type_bounds`) - #109562 (Update ar_archive_writer to 0.1.3) - #109629 (remove obsolete `givens` from regionck) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/core/src/array')
| -rw-r--r-- | library/core/src/array/iter.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 8259c087d22..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,12 +285,11 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> { self.next_back() } - fn advance_by(&mut self, n: usize) -> Result<(), usize> { - let original_len = self.len(); - + 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); + let remaining = n - range_to_drop.len(); // SAFETY: These elements are currently initialized, so it's fine to drop them. unsafe { @@ -297,7 +297,7 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> { ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(slice)); } - if n > original_len { Err(original_len) } else { Ok(()) } + NonZeroUsize::new(remaining).map_or(Ok(()), Err) } } @@ -334,12 +334,11 @@ impl<T, const N: usize> DoubleEndedIterator for IntoIter<T, N> { }) } - fn advance_back_by(&mut self, n: usize) -> Result<(), usize> { - let original_len = self.len(); - + 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); + let remaining = n - range_to_drop.len(); // SAFETY: These elements are currently initialized, so it's fine to drop them. unsafe { @@ -347,7 +346,7 @@ impl<T, const N: usize> DoubleEndedIterator for IntoIter<T, N> { ptr::drop_in_place(MaybeUninit::slice_assume_init_mut(slice)); } - if n > original_len { Err(original_len) } else { Ok(()) } + NonZeroUsize::new(remaining).map_or(Ok(()), Err) } } |
