Skip to content

Commit 92a5a90

Browse files
committed
This doesnt produce an error
1 parent 81622c6 commit 92a5a90

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/libcore/iter/mod.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,9 +1368,8 @@ impl<I: Iterator, P> Iterator for Filter<I, P> where P: FnMut(&I::Item) -> bool
13681368
}
13691369

13701370
#[inline]
1371-
fn size_hint(&self) -> (usize, Option<usize>) {
1372-
let (_, upper) = self.iter.size_hint();
1373-
(0, upper) // can't know a lower bound, due to the predicate
1371+
default fn size_hint(&self) -> (usize, Option<usize>) {
1372+
FilterImpl::size_hint(self)
13741373
}
13751374

13761375
// this special case allows the compiler to make `.filter(_).count()`
@@ -1418,6 +1417,39 @@ impl<I: Iterator, P> Iterator for Filter<I, P> where P: FnMut(&I::Item) -> bool
14181417
}
14191418
}
14201419

1420+
use ops::RangeFrom;
1421+
///
1422+
#[unstable(feature="test", issue="0")]
1423+
pub trait FancyIter: Iterator {}
1424+
#[unstable(feature="test", issue="0")]
1425+
impl<T: Step> FancyIter for RangeFrom<T> {}
1426+
1427+
#[doc(hidden)]
1428+
trait FilterImpl {
1429+
fn size_hint(&self) -> (usize, Option<usize>);
1430+
}
1431+
1432+
#[unstable(feature="test", issue="0")]
1433+
impl<I: Iterator, P: FnMut(&I::Item) -> bool> FilterImpl for Filter<I, P> {
1434+
default fn size_hint(&self) -> (usize, Option<usize>) {
1435+
let (_, upper) = self.iter.size_hint();
1436+
(0, upper) // can't know a lower bound, due to the predicate
1437+
}
1438+
}
1439+
1440+
#[unstable(feature="test", issue="0")]
1441+
impl<I: FancyIter, P: FnMut(&I::Item) -> bool> FilterImpl for Filter<I, P> {
1442+
fn size_hint(&self) -> (usize, Option<usize>) {
1443+
(0, None)
1444+
}
1445+
}
1446+
1447+
#[allow(warnings)]
1448+
fn foo() {
1449+
let foo: isize = (0..).filter(|i| *i < 5).next().unwrap();
1450+
}
1451+
1452+
14211453
#[stable(feature = "rust1", since = "1.0.0")]
14221454
impl<I: DoubleEndedIterator, P> DoubleEndedIterator for Filter<I, P>
14231455
where P: FnMut(&I::Item) -> bool,

0 commit comments

Comments
 (0)