Skip to content

Commit 051d5b0

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

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
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ where
9090
}
9191

9292
#[unstable(issue = "none", feature = "inplace_iteration")]
93-
unsafe impl<St, F, B, S: Iterator, I: Iterator> SourceIter for Scan<I, St, F>
93+
unsafe impl<St, F, I> SourceIter for Scan<I, St, F>
9494
where
95-
I: SourceIter<Source = S>,
96-
F: FnMut(&mut St, I::Item) -> Option<B>,
95+
I: SourceIter,
9796
{
98-
type Source = S;
97+
type Source = I::Source;
9998

10099
#[inline]
101-
unsafe fn as_inner(&mut self) -> &mut S {
100+
unsafe fn as_inner(&mut self) -> &mut I::Source {
102101
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
103102
unsafe { SourceIter::as_inner(&mut self.iter) }
104103
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ where
180180
impl<I> FusedIterator for Skip<I> where I: FusedIterator {}
181181

182182
#[unstable(issue = "none", feature = "inplace_iteration")]
183-
unsafe impl<S: Iterator, I: Iterator> SourceIter for Skip<I>
183+
unsafe impl<I> SourceIter for Skip<I>
184184
where
185-
I: SourceIter<Source = S>,
185+
I: SourceIter,
186186
{
187-
type Source = S;
187+
type Source = I::Source;
188188

189189
#[inline]
190-
unsafe fn as_inner(&mut self) -> &mut S {
190+
unsafe fn as_inner(&mut self) -> &mut I::Source {
191191
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
192192
unsafe { SourceIter::as_inner(&mut self.iter) }
193193
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,14 @@ where
105105
}
106106

107107
#[unstable(issue = "none", feature = "inplace_iteration")]
108-
unsafe impl<S: Iterator, P, I: Iterator> SourceIter for SkipWhile<I, P>
108+
unsafe impl<P, I> SourceIter for SkipWhile<I, P>
109109
where
110-
P: FnMut(&I::Item) -> bool,
111-
I: SourceIter<Source = S>,
110+
I: SourceIter,
112111
{
113-
type Source = S;
112+
type Source = I::Source;
114113

115114
#[inline]
116-
unsafe fn as_inner(&mut self) -> &mut S {
115+
unsafe fn as_inner(&mut self) -> &mut I::Source {
117116
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
118117
unsafe { SourceIter::as_inner(&mut self.iter) }
119118
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ where
114114
}
115115

116116
#[unstable(issue = "none", feature = "inplace_iteration")]
117-
unsafe impl<S: Iterator, I: Iterator> SourceIter for Take<I>
117+
unsafe impl<I> SourceIter for Take<I>
118118
where
119-
I: SourceIter<Source = S>,
119+
I: SourceIter,
120120
{
121-
type Source = S;
121+
type Source = I::Source;
122122

123123
#[inline]
124-
unsafe fn as_inner(&mut self) -> &mut S {
124+
unsafe fn as_inner(&mut self) -> &mut I::Source {
125125
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
126126
unsafe { SourceIter::as_inner(&mut self.iter) }
127127
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,14 @@ where
118118
}
119119

120120
#[unstable(issue = "none", feature = "inplace_iteration")]
121-
unsafe impl<S: Iterator, P, I: Iterator> SourceIter for TakeWhile<I, P>
121+
unsafe impl<P, I> SourceIter for TakeWhile<I, P>
122122
where
123-
P: FnMut(&I::Item) -> bool,
124-
I: SourceIter<Source = S>,
123+
I: SourceIter,
125124
{
126-
type Source = S;
125+
type Source = I::Source;
127126

128127
#[inline]
129-
unsafe fn as_inner(&mut self) -> &mut S {
128+
unsafe fn as_inner(&mut self) -> &mut I::Source {
130129
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
131130
unsafe { SourceIter::as_inner(&mut self.iter) }
132131
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,16 +414,14 @@ where
414414
// Arbitrarily selects the left side of the zip iteration as extractable "source"
415415
// it would require negative trait bounds to be able to try both
416416
#[unstable(issue = "none", feature = "inplace_iteration")]
417-
unsafe impl<S, A, B> SourceIter for Zip<A, B>
417+
unsafe impl<A, B> SourceIter for Zip<A, B>
418418
where
419-
A: SourceIter<Source = S>,
420-
B: Iterator,
421-
S: Iterator,
419+
A: SourceIter,
422420
{
423-
type Source = S;
421+
type Source = A::Source;
424422

425423
#[inline]
426-
unsafe fn as_inner(&mut self) -> &mut S {
424+
unsafe fn as_inner(&mut self) -> &mut A::Source {
427425
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
428426
unsafe { SourceIter::as_inner(&mut self.a) }
429427
}

0 commit comments

Comments
 (0)