Skip to content

Commit

Permalink
Rollup merge of rust-lang#40715 - manuel-rhdt:patch-1, r=brson
Browse files Browse the repository at this point in the history
Fix doc error for ExactSizeIterator

The code example in the trait documentation of ExactSizeIterator
has an incorrect implementation of the len method that does not return
the number of times the example iterator 'Counter' will iterate. This
may confuse readers of the docs as the example code will compile but
doesn't uphold the trait's contract.

This is easily fixed by modifying the implementation of len and changing
the assert statement to actually assert the correct behaviour. I also
slightly modified a code comment to better reflect what the method
returns.
  • Loading branch information
frewsxcv authored Mar 23, 2017
2 parents 2233c6d + a8800bb commit 08134cf
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/libcore/iter/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,17 +536,17 @@ impl<'a, I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for &'a mut I {
/// # }
/// # }
/// impl ExactSizeIterator for Counter {
/// // We already have the number of iterations, so we can use it directly.
/// // We can easily calculate the remaining number of iterations.
/// fn len(&self) -> usize {
/// self.count
/// 5 - self.count
/// }
/// }
///
/// // And now we can use it!
///
/// let counter = Counter::new();
///
/// assert_eq!(0, counter.len());
/// assert_eq!(5, counter.len());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub trait ExactSizeIterator: Iterator {
Expand Down

0 comments on commit 08134cf

Please sign in to comment.