Skip to content

Commit e3ea516

Browse files
bors[bot]phimuemue
andauthored
Merge #453
453: Cleanup r=phimuemue a=phimuemue This implements some cleanups: * Do not implement `size_hint` if it could be inherited from `Iterator` * Implement `(0, internal_iter.size_hint().1)` size hints uniformly * Canonicalize return types of `next`/`next_back` Since it's "only" cleanups, I hope it is ok if I merge them right away. bors r+ Co-authored-by: philipp <[email protected]>
2 parents 275e012 + b20e790 commit e3ea516

File tree

7 files changed

+8
-25
lines changed

7 files changed

+8
-25
lines changed

src/adaptors/mod.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,6 @@ impl<B, F, I> Iterator for Batching<I, F>
403403
fn next(&mut self) -> Option<Self::Item> {
404404
(self.f)(&mut self.iter)
405405
}
406-
407-
#[inline]
408-
fn size_hint(&self) -> (usize, Option<usize>) {
409-
// No information about closue behavior
410-
(0, None)
411-
}
412406
}
413407

414408
/// An iterator adaptor that steps a number elements in the base iterator
@@ -860,8 +854,7 @@ impl<'a, I, F> Iterator for TakeWhileRef<'a, I, F>
860854
}
861855

862856
fn size_hint(&self) -> (usize, Option<usize>) {
863-
let (_, hi) = self.iter.size_hint();
864-
(0, hi)
857+
(0, self.iter.size_hint().1)
865858
}
866859
}
867860

@@ -893,8 +886,7 @@ impl<I, A> Iterator for WhileSome<I>
893886
}
894887

895888
fn size_hint(&self) -> (usize, Option<usize>) {
896-
let sh = self.iter.size_hint();
897-
(0, sh.1)
889+
(0, self.iter.size_hint().1)
898890
}
899891
}
900892

src/intersperse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<I, ElemF> Iterator for IntersperseWith<I, ElemF>
115115
{
116116
type Item = I::Item;
117117
#[inline]
118-
fn next(&mut self) -> Option<I::Item> {
118+
fn next(&mut self) -> Option<Self::Item> {
119119
if self.peek.is_some() {
120120
self.peek.take()
121121
} else {

src/peeking_take_while.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ impl<'a, I, F> Iterator for PeekingTakeWhile<'a, I, F>
104104
}
105105

106106
fn size_hint(&self) -> (usize, Option<usize>) {
107-
let (_, hi) = self.iter.size_hint();
108-
(0, hi)
107+
(0, self.iter.size_hint().1)
109108
}
110109
}
111110

src/process_results_impl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ impl<'a, I, T, E> Iterator for ProcessResults<'a, I, E>
2828
}
2929

3030
fn size_hint(&self) -> (usize, Option<usize>) {
31-
let (_, hi) = self.iter.size_hint();
32-
(0, hi)
31+
(0, self.iter.size_hint().1)
3332
}
3433
}
3534

src/rciter_impl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ impl<A, I> Iterator for RcIter<I>
6969
// To work sanely with other API that assume they own an iterator,
7070
// so it can't change in other places, we can't guarantee as much
7171
// in our size_hint. Other clones may drain values under our feet.
72-
let (_, hi) = self.rciter.borrow().size_hint();
73-
(0, hi)
72+
(0, self.rciter.borrow().size_hint().1)
7473
}
7574
}
7675

src/sources.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ impl<A, St, F> Iterator for Unfold<St, F>
131131
fn next(&mut self) -> Option<Self::Item> {
132132
(self.f)(&mut self.state)
133133
}
134-
135-
#[inline]
136-
fn size_hint(&self) -> (usize, Option<usize>) {
137-
// no possible known bounds at this point
138-
(0, None)
139-
}
140134
}
141135

142136
/// An iterator that infinitely applies function to value and yields results.

src/unique_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<I, V, F> DoubleEndedIterator for UniqueBy<I, V, F>
8181
V: Eq + Hash,
8282
F: FnMut(&I::Item) -> V
8383
{
84-
fn next_back(&mut self) -> Option<I::Item> {
84+
fn next_back(&mut self) -> Option<Self::Item> {
8585
while let Some(v) = self.iter.next_back() {
8686
let key = (self.f)(&v);
8787
if self.used.insert(key, ()).is_none() {
@@ -124,7 +124,7 @@ impl<I> DoubleEndedIterator for Unique<I>
124124
where I: DoubleEndedIterator,
125125
I::Item: Eq + Hash + Clone
126126
{
127-
fn next_back(&mut self) -> Option<I::Item> {
127+
fn next_back(&mut self) -> Option<Self::Item> {
128128
while let Some(v) = self.iter.iter.next_back() {
129129
if let Entry::Vacant(entry) = self.iter.used.entry(v) {
130130
let elt = entry.key().clone();

0 commit comments

Comments
 (0)