diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-02-03 03:27:51 -0800 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-02-04 16:44:51 -0800 |
| commit | 5bc328fdeff50b742a8136d0633924514d4d76b8 (patch) | |
| tree | 09d950684bda2a834a15b40d275f11752dcb6743 /library/core/src/slice | |
| parent | 52df0558ea349fa65036e61f0a647ea8072ec3f5 (diff) | |
| download | rust-5bc328fdeff50b742a8136d0633924514d4d76b8.tar.gz rust-5bc328fdeff50b742a8136d0633924514d4d76b8.zip | |
Allow canonicalizing the `array::map` loop in trusted cases
Diffstat (limited to 'library/core/src/slice')
| -rw-r--r-- | library/core/src/slice/iter.rs | 4 | ||||
| -rw-r--r-- | library/core/src/slice/iter/macros.rs | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index 90ab43d1289..c4317799bcc 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -7,7 +7,9 @@ use crate::cmp; use crate::cmp::Ordering; use crate::fmt; use crate::intrinsics::assume; -use crate::iter::{FusedIterator, TrustedLen, TrustedRandomAccess, TrustedRandomAccessNoCoerce}; +use crate::iter::{ + FusedIterator, TrustedLen, TrustedRandomAccess, TrustedRandomAccessNoCoerce, UncheckedIterator, +}; use crate::marker::{PhantomData, Send, Sized, Sync}; use crate::mem::{self, SizedTypeProperties}; use crate::num::NonZeroUsize; diff --git a/library/core/src/slice/iter/macros.rs b/library/core/src/slice/iter/macros.rs index 0fd57b197aa..89b92a7d597 100644 --- a/library/core/src/slice/iter/macros.rs +++ b/library/core/src/slice/iter/macros.rs @@ -384,6 +384,15 @@ macro_rules! iterator { #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl<T> TrustedLen for $name<'_, T> {} + + impl<'a, T> UncheckedIterator for $name<'a, T> { + unsafe fn next_unchecked(&mut self) -> $elem { + // SAFETY: The caller promised there's at least one more item. + unsafe { + next_unchecked!(self) + } + } + } } } |
