diff options
| author | bors <bors@rust-lang.org> | 2021-03-22 04:03:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-03-22 04:03:53 +0000 |
| commit | 142c831861ba5a995fd9de99198e7f6074b6b400 (patch) | |
| tree | 3a43c288d544f23fb39cc4f42834bea8170ebc0e /library/core/src/array | |
| parent | 35385770ae1ea86a911cc44ac43f856831e44b26 (diff) | |
| parent | 790c2ad46ac5d29903d75125679b7604dcc206fe (diff) | |
| download | rust-142c831861ba5a995fd9de99198e7f6074b6b400.tar.gz rust-142c831861ba5a995fd9de99198e7f6074b6b400.zip | |
Auto merge of #83360 - Dylan-DPC:rollup-17xulpv, r=Dylan-DPC
Rollup of 9 pull requests Successful merges: - #80193 (stabilize `feature(osstring_ascii)`) - #80771 (Make NonNull::as_ref (and friends) return refs with unbound lifetimes) - #81607 (Implement TrustedLen and TrustedRandomAccess for Range<integer>, array::IntoIter, VecDequeue's iterators) - #82554 (Fix invalid slice access in String::retain) - #82686 (Move `std::sys::unix::platform` to `std::sys::unix::ext`) - #82771 (slice: Stabilize IterMut::as_slice.) - #83329 (Cleanup LLVM debuginfo module docs) - #83336 (Fix ICE with `use clippy::a::b;`) - #83350 (Download a more recent LLVM version if `src/version` is modified) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/core/src/array')
| -rw-r--r-- | library/core/src/array/iter.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 4472fba26b9..f82454addd0 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -2,7 +2,7 @@ use crate::{ fmt, - iter::{ExactSizeIterator, FusedIterator, TrustedLen}, + iter::{ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccess}, mem::{self, MaybeUninit}, ops::Range, ptr, @@ -130,6 +130,18 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> { fn last(mut self) -> Option<Self::Item> { self.next_back() } + + #[inline] + unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item + where + Self: TrustedRandomAccess, + { + // SAFETY: Callers are only allowed to pass an index that is in bounds + // Additionally Self: TrustedRandomAccess is only implemented for T: Copy which means even + // multiple repeated reads of the same index would be safe and the + // values aree !Drop, thus won't suffer from double drops. + unsafe { self.data.get_unchecked(self.alive.start + idx).assume_init_read() } + } } #[stable(feature = "array_value_iter_impls", since = "1.40.0")] @@ -184,6 +196,17 @@ impl<T, const N: usize> FusedIterator for IntoIter<T, N> {} #[stable(feature = "array_value_iter_impls", since = "1.40.0")] unsafe impl<T, const N: usize> TrustedLen for IntoIter<T, N> {} +#[doc(hidden)] +#[unstable(feature = "trusted_random_access", issue = "none")] +// T: Copy as approximation for !Drop since get_unchecked does not update the pointers +// and thus we can't implement drop-handling +unsafe impl<T, const N: usize> TrustedRandomAccess for IntoIter<T, N> +where + T: Copy, +{ + const MAY_HAVE_SIDE_EFFECT: bool = false; +} + #[stable(feature = "array_value_iter_impls", since = "1.40.0")] impl<T: Clone, const N: usize> Clone for IntoIter<T, N> { fn clone(&self) -> Self { |
