Fix standard library for min_specialization changes

This commit is contained in:
Matthew Jasper 2021-09-30 21:42:41 +01:00
parent c8f86cad2d
commit 051d5b0118
16 changed files with 71 additions and 83 deletions

View file

@ -220,14 +220,21 @@ unsafe impl<T, A: Allocator> TrustedLen for IntoIter<T, A> {}
#[doc(hidden)] #[doc(hidden)]
#[unstable(issue = "none", feature = "std_internals")] #[unstable(issue = "none", feature = "std_internals")]
#[rustc_unsafe_specialization_marker]
pub trait NonDrop {}
// T: Copy as approximation for !Drop since get_unchecked does not advance self.ptr // T: Copy as approximation for !Drop since get_unchecked does not advance self.ptr
// and thus we can't implement drop-handling // and thus we can't implement drop-handling
// #[unstable(issue = "none", feature = "std_internals")]
impl<T: Copy> NonDrop for T {}
#[doc(hidden)]
#[unstable(issue = "none", feature = "std_internals")]
// TrustedRandomAccess (without NoCoerce) must not be implemented because // TrustedRandomAccess (without NoCoerce) must not be implemented because
// subtypes/supertypes of `T` might not be `Copy` // subtypes/supertypes of `T` might not be `NonDrop`
unsafe impl<T, A: Allocator> TrustedRandomAccessNoCoerce for IntoIter<T, A> unsafe impl<T, A: Allocator> TrustedRandomAccessNoCoerce for IntoIter<T, A>
where where
T: Copy, T: NonDrop,
{ {
const MAY_HAVE_SIDE_EFFECT: bool = false; const MAY_HAVE_SIDE_EFFECT: bool = false;
} }

View file

@ -6,24 +6,14 @@ use super::{AsIntoIter, InPlaceDrop, SpecFromIter, SpecFromIterNested, Vec};
/// Specialization marker for collecting an iterator pipeline into a Vec while reusing the /// Specialization marker for collecting an iterator pipeline into a Vec while reusing the
/// source allocation, i.e. executing the pipeline in place. /// source allocation, i.e. executing the pipeline in place.
///
/// The SourceIter parent trait is necessary for the specializing function to access the allocation
/// which is to be reused. But it is not sufficient for the specialization to be valid. See
/// additional bounds on the impl.
#[rustc_unsafe_specialization_marker] #[rustc_unsafe_specialization_marker]
pub(super) trait SourceIterMarker: SourceIter<Source: AsIntoIter> {} pub(super) trait InPlaceIterableMarker {}
// The std-internal SourceIter/InPlaceIterable traits are only implemented by chains of impl<T> InPlaceIterableMarker for T where T: InPlaceIterable {}
// Adapter<Adapter<Adapter<IntoIter>>> (all owned by core/std). Additional bounds
// on the adapter implementations (beyond `impl<I: Trait> Trait for Adapter<I>`) only depend on other
// traits already marked as specialization traits (Copy, TrustedRandomAccess, FusedIterator).
// I.e. the marker does not depend on lifetimes of user-supplied types. Modulo the Copy hole, which
// several other specializations already depend on.
impl<T> SourceIterMarker for T where T: SourceIter<Source: AsIntoIter> + InPlaceIterable {}
impl<T, I> SpecFromIter<T, I> for Vec<T> impl<T, I> SpecFromIter<T, I> for Vec<T>
where where
I: Iterator<Item = T> + SourceIterMarker, I: Iterator<Item = T> + SourceIter<Source: AsIntoIter> + InPlaceIterableMarker,
{ {
default fn from_iter(mut iterator: I) -> Self { default fn from_iter(mut iterator: I) -> Self {
// Additional requirements which cannot expressed via trait bounds. We rely on const eval // Additional requirements which cannot expressed via trait bounds. We rely on const eval

View file

@ -227,14 +227,14 @@ impl<I> FusedIterator for Enumerate<I> where I: FusedIterator {}
unsafe impl<I> TrustedLen for Enumerate<I> where I: TrustedLen {} unsafe impl<I> TrustedLen for Enumerate<I> where I: TrustedLen {}
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, I: Iterator> SourceIter for Enumerate<I> unsafe impl<I> SourceIter for Enumerate<I>
where where
I: SourceIter<Source = S>, I: SourceIter,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -135,15 +135,14 @@ where
impl<I: FusedIterator, P> FusedIterator for Filter<I, P> where P: FnMut(&I::Item) -> bool {} impl<I: FusedIterator, P> FusedIterator for Filter<I, P> where P: FnMut(&I::Item) -> bool {}
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, P, I: Iterator> SourceIter for Filter<I, P> unsafe impl<P, I> SourceIter for Filter<I, P>
where where
P: FnMut(&I::Item) -> bool, I: SourceIter,
I: SourceIter<Source = S>,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -129,15 +129,14 @@ where
impl<B, I: FusedIterator, F> FusedIterator for FilterMap<I, F> where F: FnMut(I::Item) -> Option<B> {} impl<B, I: FusedIterator, F> FusedIterator for FilterMap<I, F> where F: FnMut(I::Item) -> Option<B> {}
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, B, I: Iterator, F> SourceIter for FilterMap<I, F> unsafe impl<I, F> SourceIter for FilterMap<I, F>
where where
F: FnMut(I::Item) -> Option<B>, I: SourceIter,
I: SourceIter<Source = S>,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -149,15 +149,14 @@ where
impl<I: FusedIterator, F> FusedIterator for Inspect<I, F> where F: FnMut(&I::Item) {} impl<I: FusedIterator, F> FusedIterator for Inspect<I, F> where F: FnMut(&I::Item) {}
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, I: Iterator, F> SourceIter for Inspect<I, F> unsafe impl<I, F> SourceIter for Inspect<I, F>
where where
F: FnMut(&I::Item), I: SourceIter,
I: SourceIter<Source = S>,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -201,15 +201,14 @@ where
} }
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, B, I: Iterator, F> SourceIter for Map<I, F> unsafe impl<I, F> SourceIter for Map<I, F>
where where
F: FnMut(I::Item) -> B, I: SourceIter,
I: SourceIter<Source = S>,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -80,15 +80,14 @@ where
} }
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, B, I: Iterator, P> SourceIter for MapWhile<I, P> unsafe impl<I, P> SourceIter for MapWhile<I, P>
where where
P: FnMut(I::Item) -> Option<B>, I: SourceIter,
I: SourceIter<Source = S>,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -92,9 +92,10 @@ pub use self::zip::zip;
/// [`as_inner`]: SourceIter::as_inner /// [`as_inner`]: SourceIter::as_inner
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
#[doc(hidden)] #[doc(hidden)]
#[rustc_specialization_trait]
pub unsafe trait SourceIter { pub unsafe trait SourceIter {
/// A source stage in an iterator pipeline. /// A source stage in an iterator pipeline.
type Source: Iterator; type Source;
/// Retrieve the source of an iterator pipeline. /// Retrieve the source of an iterator pipeline.
/// ///
@ -200,14 +201,14 @@ where
} }
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, I, E> SourceIter for ResultShunt<'_, I, E> unsafe impl<I, E> SourceIter for ResultShunt<'_, I, E>
where where
I: SourceIter<Source = S>, I: SourceIter,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut Self::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -321,14 +321,14 @@ impl<I: Iterator> Peekable<I> {
unsafe impl<I> TrustedLen for Peekable<I> where I: TrustedLen {} unsafe impl<I> TrustedLen for Peekable<I> where I: TrustedLen {}
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, I: Iterator> SourceIter for Peekable<I> unsafe impl<I: Iterator> SourceIter for Peekable<I>
where where
I: SourceIter<Source = S>, I: SourceIter,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -90,15 +90,14 @@ where
} }
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<St, F, B, S: Iterator, I: Iterator> SourceIter for Scan<I, St, F> unsafe impl<St, F, I> SourceIter for Scan<I, St, F>
where where
I: SourceIter<Source = S>, I: SourceIter,
F: FnMut(&mut St, I::Item) -> Option<B>,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -180,14 +180,14 @@ where
impl<I> FusedIterator for Skip<I> where I: FusedIterator {} impl<I> FusedIterator for Skip<I> where I: FusedIterator {}
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, I: Iterator> SourceIter for Skip<I> unsafe impl<I> SourceIter for Skip<I>
where where
I: SourceIter<Source = S>, I: SourceIter,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -105,15 +105,14 @@ where
} }
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, P, I: Iterator> SourceIter for SkipWhile<I, P> unsafe impl<P, I> SourceIter for SkipWhile<I, P>
where where
P: FnMut(&I::Item) -> bool, I: SourceIter,
I: SourceIter<Source = S>,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -114,14 +114,14 @@ where
} }
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, I: Iterator> SourceIter for Take<I> unsafe impl<I> SourceIter for Take<I>
where where
I: SourceIter<Source = S>, I: SourceIter,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -118,15 +118,14 @@ where
} }
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S: Iterator, P, I: Iterator> SourceIter for TakeWhile<I, P> unsafe impl<P, I> SourceIter for TakeWhile<I, P>
where where
P: FnMut(&I::Item) -> bool, I: SourceIter,
I: SourceIter<Source = S>,
{ {
type Source = S; type Source = I::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut I::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.iter) } unsafe { SourceIter::as_inner(&mut self.iter) }
} }

View file

@ -414,16 +414,14 @@ where
// Arbitrarily selects the left side of the zip iteration as extractable "source" // Arbitrarily selects the left side of the zip iteration as extractable "source"
// it would require negative trait bounds to be able to try both // it would require negative trait bounds to be able to try both
#[unstable(issue = "none", feature = "inplace_iteration")] #[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<S, A, B> SourceIter for Zip<A, B> unsafe impl<A, B> SourceIter for Zip<A, B>
where where
A: SourceIter<Source = S>, A: SourceIter,
B: Iterator,
S: Iterator,
{ {
type Source = S; type Source = A::Source;
#[inline] #[inline]
unsafe fn as_inner(&mut self) -> &mut S { unsafe fn as_inner(&mut self) -> &mut A::Source {
// SAFETY: unsafe function forwarding to unsafe function with the same requirements // SAFETY: unsafe function forwarding to unsafe function with the same requirements
unsafe { SourceIter::as_inner(&mut self.a) } unsafe { SourceIter::as_inner(&mut self.a) }
} }