Skip to content

Commit 7c666a7

Browse files
authored
Rollup merge of rust-lang#66094 - ArturKovacs:fix-count-doc, r=Dylan-DPC
Fix documentation for `Iterator::count()`. The documentation of std::core::Iterator::count() stated that the number returned is the number of times `next` is called on the iterator. However this is not true as the number of times `next` is called is exactly one plus the number returned by `count()`.
2 parents bfcf7f6 + 23be25c commit 7c666a7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/libcore/iter/traits/iterator.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ pub trait Iterator {
201201

202202
/// Consumes the iterator, counting the number of iterations and returning it.
203203
///
204-
/// This method will evaluate the iterator until its [`next`] returns
205-
/// [`None`]. Once [`None`] is encountered, `count()` returns the number of
206-
/// times it called [`next`].
204+
/// This method will call [`next`] repeatedly until [`None`] is encountered,
205+
/// returning the number of times it saw [`Some`]. Note that [`next`] has to be
206+
/// called at least once even if the iterator does not have any elements.
207207
///
208208
/// [`next`]: #tymethod.next
209209
/// [`None`]: ../../std/option/enum.Option.html#variant.None
210+
/// [`Some`]: ../../std/option/enum.Option.html#variant.Some
210211
///
211212
/// # Overflow Behavior
212213
///

0 commit comments

Comments
 (0)