Fix Iterator::advance_by contract inconsistency#89916
Conversation
|
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
de31b95 to
17ce56f
Compare
|
@bors r+ |
|
📌 Commit 17ce56f has been approved by |
…tolnay 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`.
|
@bors r- Failed in rollup: #91024 (comment) Looks like this fails when run with overflow-checks enabled. |
|
The reason CI checks are green here is because overflow checks were added after this PR was submitted (in #89776). |
17ce56f to
04cecdf
Compare
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`.
04cecdf to
3f9b26d
Compare
|
@bors r+ |
|
📌 Commit 3f9b26d has been approved by |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (5fd3a5c): comparison url. Summary: This benchmark run did not return any relevant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
|
Thanks for all the reviews @dtolnay |
The
advance_by(n)docs state that in the error caseErr(k)that k is always less than n.It also states that
advance_by(0)may returnErr(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.