@@ -751,6 +751,7 @@ impl<A, B, T: ExactSize<A>, U: ExactSize<B>> ExactSize<(A, B)> for Zip<T, U> {}
751751
752752/// An double-ended iterator with the direction inverted
753753#[ deriving( Clone ) ]
754+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
754755pub struct Rev < T > {
755756 iter : T
756757}
@@ -779,6 +780,7 @@ impl<A, T: DoubleEndedIterator<A> + RandomAccessIterator<A>> RandomAccessIterato
779780}
780781
781782/// A mutable reference to an iterator
783+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
782784pub struct ByRef < ' a , T > {
783785 iter : & ' a mut T
784786}
@@ -1039,6 +1041,7 @@ impl<A, T: Clone + Iterator<A>> CloneableIterator for T {
10391041
10401042/// An iterator that repeats endlessly
10411043#[ deriving( Clone ) ]
1044+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
10421045pub struct Cycle < T > {
10431046 orig : T ,
10441047 iter : T ,
@@ -1090,6 +1093,7 @@ impl<A, T: Clone + RandomAccessIterator<A>> RandomAccessIterator<A> for Cycle<T>
10901093
10911094/// An iterator which strings two iterators together
10921095#[ deriving( Clone ) ]
1096+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
10931097pub struct Chain < T , U > {
10941098 a : T ,
10951099 b : U ,
@@ -1159,6 +1163,7 @@ for Chain<T, U> {
11591163
11601164/// An iterator which iterates two other iterators simultaneously
11611165#[ deriving( Clone ) ]
1166+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
11621167pub struct Zip < T , U > {
11631168 a : T ,
11641169 b : U
@@ -1237,6 +1242,7 @@ RandomAccessIterator<(A, B)> for Zip<T, U> {
12371242}
12381243
12391244/// An iterator which maps the values of `iter` with `f`
1245+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
12401246pub struct Map < ' a , A , B , T > {
12411247 iter : T ,
12421248 f : |A |: ' a -> B
@@ -1287,6 +1293,7 @@ impl<'a, A, B, T: RandomAccessIterator<A>> RandomAccessIterator<B> for Map<'a, A
12871293}
12881294
12891295/// An iterator which filters the elements of `iter` with `predicate`
1296+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
12901297pub struct Filter < ' a , A , T > {
12911298 iter : T ,
12921299 predicate : |& A |: ' a -> bool
@@ -1331,6 +1338,7 @@ impl<'a, A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Filter<'a, A,
13311338}
13321339
13331340/// An iterator which uses `f` to both filter and map elements from `iter`
1341+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
13341342pub struct FilterMap < ' a , A , B , T > {
13351343 iter : T ,
13361344 f : |A |: ' a -> Option <B >
@@ -1375,6 +1383,7 @@ for FilterMap<'a, A, B, T> {
13751383
13761384/// An iterator which yields the current count and the element during iteration
13771385#[ deriving( Clone ) ]
1386+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
13781387pub struct Enumerate < T > {
13791388 iter : T ,
13801389 count : uint
@@ -1429,6 +1438,7 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<(uint, A)> for Enumerat
14291438}
14301439
14311440/// An iterator with a `peek()` that returns an optional reference to the next element.
1441+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
14321442pub struct Peekable < A , T > {
14331443 iter : T ,
14341444 peeked : Option < A > ,
@@ -1479,6 +1489,7 @@ impl<'a, A, T: Iterator<A>> Peekable<A, T> {
14791489}
14801490
14811491/// An iterator which rejects elements while `predicate` is true
1492+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
14821493pub struct SkipWhile < ' a , A , T > {
14831494 iter : T ,
14841495 flag : bool ,
@@ -1517,6 +1528,7 @@ impl<'a, A, T: Iterator<A>> Iterator<A> for SkipWhile<'a, A, T> {
15171528}
15181529
15191530/// An iterator which only accepts elements while `predicate` is true
1531+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
15201532pub struct TakeWhile < ' a , A , T > {
15211533 iter : T ,
15221534 flag : bool ,
@@ -1552,6 +1564,7 @@ impl<'a, A, T: Iterator<A>> Iterator<A> for TakeWhile<'a, A, T> {
15521564
15531565/// An iterator which skips over `n` elements of `iter`.
15541566#[ deriving( Clone ) ]
1567+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
15551568pub struct Skip < T > {
15561569 iter : T ,
15571570 n : uint
@@ -1616,6 +1629,7 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Skip<T> {
16161629
16171630/// An iterator which only iterates over the first `n` iterations of `iter`.
16181631#[ deriving( Clone ) ]
1632+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
16191633pub struct Take < T > {
16201634 iter : T ,
16211635 n : uint
@@ -1665,6 +1679,7 @@ impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Take<T> {
16651679
16661680
16671681/// An iterator to maintain state while iterating another iterator
1682+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
16681683pub struct Scan < ' a , A , B , T , St > {
16691684 iter : T ,
16701685 f : |& mut St , A |: ' a -> Option <B >,
@@ -1689,6 +1704,7 @@ impl<'a, A, B, T: Iterator<A>, St> Iterator<B> for Scan<'a, A, B, T, St> {
16891704/// An iterator that maps each element to an iterator,
16901705/// and yields the elements of the produced iterators
16911706///
1707+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
16921708pub struct FlatMap < ' a , A , T , U > {
16931709 iter : T ,
16941710 f : |A |: ' a -> U ,
@@ -1748,6 +1764,7 @@ impl<'a,
17481764/// An iterator that yields `None` forever after the underlying iterator
17491765/// yields `None` once.
17501766#[ deriving( Clone ) ]
1767+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
17511768pub struct Fuse < T > {
17521769 iter : T ,
17531770 done : bool
@@ -1820,6 +1837,7 @@ impl<T> Fuse<T> {
18201837
18211838/// An iterator that calls a function with a reference to each
18221839/// element before yielding it.
1840+ #[ must_use = "iterator adaptors are lazy and do nothing unless consumed" ]
18231841pub struct Inspect < ' a , A , T > {
18241842 iter : T ,
18251843 f : |& A |: ' a
@@ -2299,4 +2317,3 @@ pub mod order {
22992317 }
23002318 }
23012319}
2302-
0 commit comments