Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 051d5b0

Browse files
committed
Fix standard library for min_specialization changes
1 parent c8f86ca commit 051d5b0

File tree

16 files changed

+71
-83
lines changed

16 files changed

+71
-83
lines changed

library/alloc/src/vec/into_iter.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,21 @@ unsafe impl<T, A: Allocator> TrustedLen for IntoIter<T, A> {}
220220

221221
#[doc(hidden)]
222222
#[unstable(issue = "none", feature = "std_internals")]
223+
#[rustc_unsafe_specialization_marker]
224+
pub trait NonDrop {}
225+
223226
// T: Copy as approximation for !Drop since get_unchecked does not advance self.ptr
224227
// and thus we can't implement drop-handling
225-
//
228+
#[unstable(issue = "none", feature = "std_internals")]
229+
impl<T: Copy> NonDrop for T {}
230+
231+
#[doc(hidden)]
232+
#[unstable(issue = "none", feature = "std_internals")]
226233
// TrustedRandomAccess (without NoCoerce) must not be implemented because
227-
// subtypes/supertypes of `T` might not be `Copy`
234+
// subtypes/supertypes of `T` might not be `NonDrop`
228235
unsafe impl<T, A: Allocator> TrustedRandomAccessNoCoerce for IntoIter<T, A>
229236
where
230-
T: Copy,
237+
T: NonDrop,
231238
{
232239
const MAY_HAVE_SIDE_EFFECT: bool = false;
233240
}

library/alloc/src/vec/source_iter_marker.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,14 @@ use super::{AsIntoIter, InPlaceDrop, SpecFromIter, SpecFromIterNested, Vec};
66

77
/// Specialization marker for collecting an iterator pipeline into a Vec while reusing the
88
/// source allocation, i.e. executing the pipeline in place.
9-
///
10-
/// The SourceIter parent trait is necessary for the specializing function to access the allocation
11-
/// which is to be reused. But it is not sufficient for the specialization to be valid. See
12-
/// additional bounds on the impl.
139
#[rustc_unsafe_specialization_marker]
14-
pub(super) trait SourceIterMarker: SourceIter<Source: AsIntoIter> {}
10+
pub(super) trait InPlaceIterableMarker {}
1511

16-
// The std-internal SourceIter/InPlaceIterable traits are only implemented by chains of
17-
// Adapter<Adapter<Adapter<IntoIter>>> (all owned by core/std). Additional bounds
18-
// on the adapter implementations (beyond `impl<I: Trait> Trait for Adapter<I>`) only depend on other
19-
// traits already marked as specialization traits (Copy, TrustedRandomAccess, FusedIterator).
20-
// I.e. the marker does not depend on lifetimes of user-supplied types. Modulo the Copy hole, which
21-
// several other specializations already depend on.
22-
impl<T> SourceIterMarker for T where T: SourceIter<Source: AsIntoIter> + InPlaceIterable {}
12+
impl<T> InPlaceIterableMarker for T where T: InPlaceIterable {}
2313

2414
impl<T, I> SpecFromIter<T, I> for Vec<T>
2515
where
26-
I: Iterator<Item = T> + SourceIterMarker,
16+
I: Iterator<Item = T> + SourceIter<Source: AsIntoIter> + InPlaceIterableMarker,
2717
{
2818
default fn from_iter(mut iterator: I) -> Self {
2919
// Additional requirements which cannot expressed via trait bounds. We rely on const eval

library/core/src/iter/adapters/enumerate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ impl<I> FusedIterator for Enumerate<I> where I: FusedIterator {}
227227
unsafe impl<I> TrustedLen for Enumerate<I> where I: TrustedLen {}
228228

229229
#[unstable(issue = "none", feature = "inplace_iteration")]
230-
unsafe impl<S: Iterator, I: Iterator> SourceIter for Enumerate<I>
230+
unsafe impl<I> SourceIter for Enumerate<I>
231231
where
232-
I: SourceIter<Source = S>,
232+
I: SourceIter,
233233
{
234-
type Source = S;
234+
type Source = I::Source;
235235

236236
#[inline]
237-
unsafe fn as_inner(&mut self) -> &mut S {
237+
unsafe fn as_inner(&mut self) -> &mut I::Source {
238238
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
239239
unsafe { SourceIter::as_inner(&mut self.iter) }
240240
}

library/core/src/iter/adapters/filter.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,14 @@ where
135135
impl<I: FusedIterator, P> FusedIterator for Filter<I, P> where P: FnMut(&I::Item) -> bool {}
136136

137137
#[unstable(issue = "none", feature = "inplace_iteration")]
138-
unsafe impl<S: Iterator, P, I: Iterator> SourceIter for Filter<I, P>
138+
unsafe impl<P, I> SourceIter for Filter<I, P>
139139
where
140-
P: FnMut(&I::Item) -> bool,
141-
I: SourceIter<Source = S>,
140+
I: SourceIter,
142141
{
143-
type Source = S;
142+
type Source = I::Source;
144143

145144
#[inline]
146-
unsafe fn as_inner(&mut self) -> &mut S {
145+
unsafe fn as_inner(&mut self) -> &mut I::Source {
147146
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
148147
unsafe { SourceIter::as_inner(&mut self.iter) }
149148
}

library/core/src/iter/adapters/filter_map.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,14 @@ where
129129
impl<B, I: FusedIterator, F> FusedIterator for FilterMap<I, F> where F: FnMut(I::Item) -> Option<B> {}
130130

131131
#[unstable(issue = "none", feature = "inplace_iteration")]
132-
unsafe impl<S: Iterator, B, I: Iterator, F> SourceIter for FilterMap<I, F>
132+
unsafe impl<I, F> SourceIter for FilterMap<I, F>
133133
where
134-
F: FnMut(I::Item) -> Option<B>,
135-
I: SourceIter<Source = S>,
134+
I: SourceIter,
136135
{
137-
type Source = S;
136+
type Source = I::Source;
138137

139138
#[inline]
140-
unsafe fn as_inner(&mut self) -> &mut S {
139+
unsafe fn as_inner(&mut self) -> &mut I::Source {
141140
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
142141
unsafe { SourceIter::as_inner(&mut self.iter) }
143142
}

library/core/src/iter/adapters/inspect.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,14 @@ where
149149
impl<I: FusedIterator, F> FusedIterator for Inspect<I, F> where F: FnMut(&I::Item) {}
150150

151151
#[unstable(issue = "none", feature = "inplace_iteration")]
152-
unsafe impl<S: Iterator, I: Iterator, F> SourceIter for Inspect<I, F>
152+
unsafe impl<I, F> SourceIter for Inspect<I, F>
153153
where
154-
F: FnMut(&I::Item),
155-
I: SourceIter<Source = S>,
154+
I: SourceIter,
156155
{
157-
type Source = S;
156+
type Source = I::Source;
158157

159158
#[inline]
160-
unsafe fn as_inner(&mut self) -> &mut S {
159+
unsafe fn as_inner(&mut self) -> &mut I::Source {
161160
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
162161
unsafe { SourceIter::as_inner(&mut self.iter) }
163162
}

library/core/src/iter/adapters/map.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,14 @@ where
201201
}
202202

203203
#[unstable(issue = "none", feature = "inplace_iteration")]
204-
unsafe impl<S: Iterator, B, I: Iterator, F> SourceIter for Map<I, F>
204+
unsafe impl<I, F> SourceIter for Map<I, F>
205205
where
206-
F: FnMut(I::Item) -> B,
207-
I: SourceIter<Source = S>,
206+
I: SourceIter,
208207
{
209-
type Source = S;
208+
type Source = I::Source;
210209

211210
#[inline]
212-
unsafe fn as_inner(&mut self) -> &mut S {
211+
unsafe fn as_inner(&mut self) -> &mut I::Source {
213212
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
214213
unsafe { SourceIter::as_inner(&mut self.iter) }
215214
}

library/core/src/iter/adapters/map_while.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ where
8080
}
8181

8282
#[unstable(issue = "none", feature = "inplace_iteration")]
83-
unsafe impl<S: Iterator, B, I: Iterator, P> SourceIter for MapWhile<I, P>
83+
unsafe impl<I, P> SourceIter for MapWhile<I, P>
8484
where
85-
P: FnMut(I::Item) -> Option<B>,
86-
I: SourceIter<Source = S>,
85+
I: SourceIter,
8786
{
88-
type Source = S;
87+
type Source = I::Source;
8988

9089
#[inline]
91-
unsafe fn as_inner(&mut self) -> &mut S {
90+
unsafe fn as_inner(&mut self) -> &mut I::Source {
9291
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
9392
unsafe { SourceIter::as_inner(&mut self.iter) }
9493
}

library/core/src/iter/adapters/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ pub use self::zip::zip;
9292
/// [`as_inner`]: SourceIter::as_inner
9393
#[unstable(issue = "none", feature = "inplace_iteration")]
9494
#[doc(hidden)]
95+
#[rustc_specialization_trait]
9596
pub unsafe trait SourceIter {
9697
/// A source stage in an iterator pipeline.
97-
type Source: Iterator;
98+
type Source;
9899

99100
/// Retrieve the source of an iterator pipeline.
100101
///
@@ -200,14 +201,14 @@ where
200201
}
201202

202203
#[unstable(issue = "none", feature = "inplace_iteration")]
203-
unsafe impl<S: Iterator, I, E> SourceIter for ResultShunt<'_, I, E>
204+
unsafe impl<I, E> SourceIter for ResultShunt<'_, I, E>
204205
where
205-
I: SourceIter<Source = S>,
206+
I: SourceIter,
206207
{
207-
type Source = S;
208+
type Source = I::Source;
208209

209210
#[inline]
210-
unsafe fn as_inner(&mut self) -> &mut S {
211+
unsafe fn as_inner(&mut self) -> &mut Self::Source {
211212
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
212213
unsafe { SourceIter::as_inner(&mut self.iter) }
213214
}

library/core/src/iter/adapters/peekable.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,14 @@ impl<I: Iterator> Peekable<I> {
321321
unsafe impl<I> TrustedLen for Peekable<I> where I: TrustedLen {}
322322

323323
#[unstable(issue = "none", feature = "inplace_iteration")]
324-
unsafe impl<S: Iterator, I: Iterator> SourceIter for Peekable<I>
324+
unsafe impl<I: Iterator> SourceIter for Peekable<I>
325325
where
326-
I: SourceIter<Source = S>,
326+
I: SourceIter,
327327
{
328-
type Source = S;
328+
type Source = I::Source;
329329

330330
#[inline]
331-
unsafe fn as_inner(&mut self) -> &mut S {
331+
unsafe fn as_inner(&mut self) -> &mut I::Source {
332332
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
333333
unsafe { SourceIter::as_inner(&mut self.iter) }
334334
}

0 commit comments

Comments
 (0)