]> git.lizzy.rs Git - rust.git/commit
Fix Iterator::advance_by contract inconsistency
authorThe8472 <git@infinite-source.de>
Thu, 14 Oct 2021 10:10:18 +0000 (12:10 +0200)
committerThe8472 <git@infinite-source.de>
Fri, 19 Nov 2021 12:00:23 +0000 (13:00 +0100)
commit3f9b26dc64a2068d30027fd29ffbbfe07663419f
tree789ec818eeb3d78cf2c901ddf2c430daeb5f0152
parentcc946fcd326f7d85d4af096efdc73538622568e9
Fix Iterator::advance_by contract inconsistency

The `advance_by(n)` docs state that in the error case `Err(k)` that k is always less than n.
It also states that `advance_by(0)` may return `Err(0)` to indicate an exhausted iterator.
These statements are inconsistent.
Since only one implementation (Skip) actually made use of that I changed it to return Ok(()) in that case too.

While adding some tests I also found a bug in `Take::advance_back_by`.
library/alloc/tests/vec.rs
library/core/src/iter/adapters/skip.rs
library/core/src/iter/adapters/take.rs
library/core/src/iter/traits/double_ended.rs
library/core/src/iter/traits/iterator.rs
library/core/tests/iter/adapters/chain.rs
library/core/tests/iter/adapters/flatten.rs
library/core/tests/iter/adapters/skip.rs
library/core/tests/iter/adapters/take.rs
library/core/tests/iter/range.rs
library/core/tests/slice.rs