Skip to content

Commit 0597339

Browse files
committed
refactor: removed ZipImpl
1 parent bfb0e4a commit 0597339

File tree

1 file changed

+12
-55
lines changed
  • library/core/src/iter/adapters

1 file changed

+12
-55
lines changed

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

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ pub struct Zip<A, B> {
1717
index: usize,
1818
len: usize,
1919
}
20-
impl<A: Iterator, B: Iterator> Zip<A, B> {
20+
21+
impl<A, B> Zip<A, B>
22+
where
23+
A: Iterator,
24+
B: Iterator,
25+
{
2126
pub(in crate::iter) fn new(a: A, b: B) -> Zip<A, B> {
2227
ZipNew::new(a, b)
2328
}
@@ -66,40 +71,6 @@ where
6671
}
6772
}
6873

69-
#[stable(feature = "rust1", since = "1.0.0")]
70-
impl<A, B> Iterator for Zip<A, B>
71-
where
72-
A: Iterator,
73-
B: Iterator,
74-
{
75-
type Item = (A::Item, B::Item);
76-
77-
#[inline]
78-
fn next(&mut self) -> Option<Self::Item> {
79-
ZipImpl::next(self)
80-
}
81-
82-
#[inline]
83-
fn size_hint(&self) -> (usize, Option<usize>) {
84-
ZipImpl::size_hint(self)
85-
}
86-
87-
#[inline]
88-
fn nth(&mut self, n: usize) -> Option<Self::Item> {
89-
ZipImpl::nth(self, n)
90-
}
91-
92-
#[inline]
93-
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
94-
where
95-
Self: TrustedRandomAccess,
96-
{
97-
// SAFETY: `ZipImpl::__iterator_get_unchecked` has same safety
98-
// requirements as `Iterator::__iterator_get_unchecked`.
99-
unsafe { ZipImpl::get_unchecked(self, idx) }
100-
}
101-
}
102-
10374
#[stable(feature = "rust1", since = "1.0.0")]
10475
impl<A, B> DoubleEndedIterator for Zip<A, B>
10576
where
@@ -175,22 +146,8 @@ where
175146
}
176147
}
177148

178-
// Zip specialization trait
179-
#[doc(hidden)]
180-
trait ZipImpl<A, B> {
181-
type Item;
182-
fn next(&mut self) -> Option<Self::Item>;
183-
fn size_hint(&self) -> (usize, Option<usize>);
184-
fn nth(&mut self, n: usize) -> Option<Self::Item>;
185-
// This has the same safety requirements as `Iterator::__iterator_get_unchecked`
186-
unsafe fn get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item
187-
where
188-
Self: Iterator + TrustedRandomAccess;
189-
}
190-
191-
// General Zip impl
192-
#[doc(hidden)]
193-
impl<A, B> ZipImpl<A, B> for Zip<A, B>
149+
#[stable(feature = "rust1", since = "1.0.0")]
150+
impl<A, B> Iterator for Zip<A, B>
194151
where
195152
A: Iterator,
196153
B: Iterator,
@@ -226,16 +183,16 @@ where
226183
(lower, upper)
227184
}
228185

229-
default unsafe fn get_unchecked(&mut self, _idx: usize) -> <Self as Iterator>::Item
186+
default unsafe fn __iterator_get_unchecked(&mut self, _idx: usize) -> <Self as Iterator>::Item
230187
where
231188
Self: TrustedRandomAccess,
232189
{
233190
unreachable!("Always specialized");
234191
}
235192
}
236193

237-
#[doc(hidden)]
238-
impl<A, B> ZipImpl<A, B> for Zip<A, B>
194+
#[stable(feature = "rust1", since = "1.0.0")]
195+
impl<A, B> Iterator for Zip<A, B>
239196
where
240197
A: TrustedRandomAccess + Iterator,
241198
B: TrustedRandomAccess + Iterator,
@@ -295,7 +252,7 @@ where
295252
}
296253

297254
#[inline]
298-
unsafe fn get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item {
255+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item {
299256
let idx = self.index + idx;
300257
// SAFETY: the caller must uphold the contract for
301258
// `Iterator::__iterator_get_unchecked`.

0 commit comments

Comments
 (0)