mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-30 13:06:28 +03:00
Remove UncheckedIterator
The last usage of this trait was removed in a previous commit.
This commit is contained in:
@@ -6,8 +6,7 @@ impl<'l, 'f, T, U, F: FnMut(T) -> U> Drain<'l, 'f, T, F> {
|
||||
/// This function returns a function that lets you index the given array in const.
|
||||
/// As implemented it can optimize better than iterators, and can be constified.
|
||||
/// It acts like a sort of guard (owns the array) and iterator combined, which can be implemented
|
||||
/// as it is a struct that implements const fn;
|
||||
/// in that regard it is somewhat similar to an array::Iter implementing `UncheckedIterator`.
|
||||
/// as it is a struct that implements const fn.
|
||||
/// The only method you're really allowed to call is `next()`,
|
||||
/// anything else is more or less UB, hence this function being unsafe.
|
||||
/// Moved elements will not be dropped.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::iter::adapters::zip::try_get_unchecked;
|
||||
use crate::iter::adapters::{SourceIter, TrustedRandomAccess, TrustedRandomAccessNoCoerce};
|
||||
use crate::iter::{FusedIterator, InPlaceIterable, TrustedLen, UncheckedIterator};
|
||||
use crate::iter::{FusedIterator, InPlaceIterable, TrustedLen};
|
||||
use crate::ops::Try;
|
||||
|
||||
/// An iterator that clones the elements of an underlying iterator.
|
||||
@@ -142,19 +142,6 @@ unsafe impl<'a, I, T: 'a> TrustedLen for Cloned<I>
|
||||
{
|
||||
}
|
||||
|
||||
impl<'a, I, T: 'a> UncheckedIterator for Cloned<I>
|
||||
where
|
||||
I: UncheckedIterator<Item = &'a T>,
|
||||
T: Clone,
|
||||
{
|
||||
unsafe fn next_unchecked(&mut self) -> T {
|
||||
// SAFETY: `Cloned` is 1:1 with the inner iterator, so if the caller promised
|
||||
// that there's an element left, the inner iterator has one too.
|
||||
let item = unsafe { self.it.next_unchecked() };
|
||||
item.clone()
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "default_iters", since = "1.70.0")]
|
||||
impl<I: Default> Default for Cloned<I> {
|
||||
/// Creates a `Cloned` iterator from the default value of `I`
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::fmt;
|
||||
use crate::iter::adapters::zip::try_get_unchecked;
|
||||
use crate::iter::adapters::{SourceIter, TrustedRandomAccess, TrustedRandomAccessNoCoerce};
|
||||
use crate::iter::{FusedIterator, InPlaceIterable, TrustedFused, TrustedLen, UncheckedIterator};
|
||||
use crate::iter::{FusedIterator, InPlaceIterable, TrustedFused, TrustedLen};
|
||||
use crate::num::NonZero;
|
||||
use crate::ops::Try;
|
||||
|
||||
@@ -194,19 +194,6 @@ unsafe impl<B, I, F> TrustedLen for Map<I, F>
|
||||
{
|
||||
}
|
||||
|
||||
impl<B, I, F> UncheckedIterator for Map<I, F>
|
||||
where
|
||||
I: UncheckedIterator,
|
||||
F: FnMut(I::Item) -> B,
|
||||
{
|
||||
unsafe fn next_unchecked(&mut self) -> B {
|
||||
// SAFETY: `Map` is 1:1 with the inner iterator, so if the caller promised
|
||||
// that there's an element left, the inner iterator has one too.
|
||||
let item = unsafe { self.iter.next_unchecked() };
|
||||
(self.f)(item)
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[unstable(feature = "trusted_random_access", issue = "none")]
|
||||
unsafe impl<I, F> TrustedRandomAccess for Map<I, F> where I: TrustedRandomAccess {}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use crate::cmp;
|
||||
use crate::fmt::{self, Debug};
|
||||
use crate::iter::{
|
||||
FusedIterator, InPlaceIterable, SourceIter, TrustedFused, TrustedLen, UncheckedIterator,
|
||||
};
|
||||
use crate::iter::{FusedIterator, InPlaceIterable, SourceIter, TrustedFused, TrustedLen};
|
||||
use crate::num::NonZero;
|
||||
|
||||
/// An iterator that iterates two other iterators simultaneously.
|
||||
@@ -456,13 +454,6 @@ unsafe impl<A, B> TrustedLen for Zip<A, B>
|
||||
{
|
||||
}
|
||||
|
||||
impl<A, B> UncheckedIterator for Zip<A, B>
|
||||
where
|
||||
A: UncheckedIterator,
|
||||
B: UncheckedIterator,
|
||||
{
|
||||
}
|
||||
|
||||
// Arbitrarily selects the left side of the zip iteration as extractable "source"
|
||||
// it would require negative trait bounds to be able to try both
|
||||
#[unstable(issue = "none", feature = "inplace_iteration")]
|
||||
|
||||
@@ -458,7 +458,6 @@ fn $fold<AAA, FFF>(mut self, init: AAA, fold: FFF) -> AAA
|
||||
pub use self::traits::TrustedLen;
|
||||
#[unstable(feature = "trusted_step", issue = "85731")]
|
||||
pub use self::traits::TrustedStep;
|
||||
pub(crate) use self::traits::UncheckedIterator;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub use self::traits::{
|
||||
DoubleEndedIterator, ExactSizeIterator, Extend, FromIterator, IntoIterator, Product, Sum,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::fmt;
|
||||
use crate::iter::{FusedIterator, TrustedLen, UncheckedIterator};
|
||||
use crate::iter::{FusedIterator, TrustedLen};
|
||||
use crate::num::NonZero;
|
||||
use crate::ops::Try;
|
||||
|
||||
@@ -211,5 +211,3 @@ impl<A: Clone> FusedIterator for RepeatN<A> {}
|
||||
|
||||
#[unstable(feature = "trusted_len", issue = "37572")]
|
||||
unsafe impl<A: Clone> TrustedLen for RepeatN<A> {}
|
||||
#[stable(feature = "iter_repeat_n", since = "1.82.0")]
|
||||
impl<A: Clone> UncheckedIterator for RepeatN<A> {}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
mod exact_size;
|
||||
mod iterator;
|
||||
mod marker;
|
||||
mod unchecked_iterator;
|
||||
|
||||
#[unstable(issue = "none", feature = "inplace_iteration")]
|
||||
pub use self::marker::InPlaceIterable;
|
||||
@@ -12,7 +11,6 @@
|
||||
pub use self::marker::TrustedFused;
|
||||
#[unstable(feature = "trusted_step", issue = "85731")]
|
||||
pub use self::marker::TrustedStep;
|
||||
pub(crate) use self::unchecked_iterator::UncheckedIterator;
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub use self::{
|
||||
accum::{Product, Sum},
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
use crate::iter::TrustedLen;
|
||||
|
||||
/// [`TrustedLen`] cannot have methods, so this allows augmenting it.
|
||||
///
|
||||
/// It currently requires `TrustedLen` because it's unclear whether it's
|
||||
/// reasonably possible to depend on the `size_hint` of anything else.
|
||||
pub(crate) trait UncheckedIterator: TrustedLen {
|
||||
/// Gets the next item from a non-empty iterator.
|
||||
///
|
||||
/// Because there's always a value to return, that means it can return
|
||||
/// the `Item` type directly, without wrapping it in an `Option`.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This can only be called if `size_hint().0 != 0`, guaranteeing that
|
||||
/// there's at least one item available.
|
||||
///
|
||||
/// Otherwise (aka when `size_hint().1 == Some(0)`), this is UB.
|
||||
///
|
||||
/// # Note to Implementers
|
||||
///
|
||||
/// This has a default implementation using [`Option::unwrap_unchecked`].
|
||||
/// That's probably sufficient if your `next` *always* returns `Some`,
|
||||
/// such as for infinite iterators. In more complicated situations, however,
|
||||
/// sometimes there can still be `insertvalue`/`assume`/`extractvalue`
|
||||
/// instructions remaining in the IR from the `Option` handling, at which
|
||||
/// point you might want to implement this manually instead.
|
||||
#[unstable(feature = "trusted_len_next_unchecked", issue = "37572")]
|
||||
#[inline]
|
||||
unsafe fn next_unchecked(&mut self) -> Self::Item {
|
||||
let opt = self.next();
|
||||
// SAFETY: The caller promised that we're not empty, and
|
||||
// `Self: TrustedLen` so we can actually trust the `size_hint`.
|
||||
unsafe { opt.unwrap_unchecked() }
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,7 @@
|
||||
|
||||
use super::{from_raw_parts, from_raw_parts_mut};
|
||||
use crate::hint::assert_unchecked;
|
||||
use crate::iter::{
|
||||
FusedIterator, TrustedLen, TrustedRandomAccess, TrustedRandomAccessNoCoerce, UncheckedIterator,
|
||||
};
|
||||
use crate::iter::{FusedIterator, TrustedLen, TrustedRandomAccess, TrustedRandomAccessNoCoerce};
|
||||
use crate::marker::PhantomData;
|
||||
use crate::mem::{self, SizedTypeProperties};
|
||||
use crate::num::NonZero;
|
||||
|
||||
@@ -238,7 +238,7 @@ fn nth(&mut self, n: usize) -> Option<$elem> {
|
||||
// SAFETY: We are in bounds. `post_inc_start` does the right thing even for ZSTs.
|
||||
unsafe {
|
||||
self.post_inc_start(n);
|
||||
Some(self.next_unchecked())
|
||||
Some(self.post_inc_start(1).$into_ref())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -481,16 +481,6 @@ impl<T> FusedIterator for $name<'_, T> {}
|
||||
#[unstable(feature = "trusted_len", issue = "37572")]
|
||||
unsafe impl<T> TrustedLen for $name<'_, T> {}
|
||||
|
||||
impl<'a, T> UncheckedIterator for $name<'a, T> {
|
||||
#[inline]
|
||||
unsafe fn next_unchecked(&mut self) -> $elem {
|
||||
// SAFETY: The caller promised there's at least one more item.
|
||||
unsafe {
|
||||
self.post_inc_start(1).$into_ref()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "default_iters", since = "1.70.0")]
|
||||
impl<T> Default for $name<'_, T> {
|
||||
/// Creates an empty slice iterator.
|
||||
|
||||
Reference in New Issue
Block a user