Skip to content

Fix Iterator::advance_by contract inconsistency - #89916

Merged
bors merged 1 commit into
rust-lang:masterfrom
the8472:advance_by-avoid-err-0
Nov 27, 2021
Merged

Fix Iterator::advance_by contract inconsistency#89916
bors merged 1 commit into
rust-lang:masterfrom
the8472:advance_by-avoid-err-0

Conversation

@the8472

Copy link
Copy Markdown
Member

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.

@the8472the8472 added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Oct 15, 2021
@rust-highfive

Copy link
Copy Markdown
Contributor

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 15, 2021
@the8472
the8472force-pushed the advance_by-avoid-err-0 branch from de31b95 to 17ce56fCompareOctober 15, 2021 15:48
@JohnCSimonJohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 31, 2021
@the8472the8472 mentioned this pull request Nov 18, 2021

@dtolnaydtolnay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I also noticed in #91000 that the "k always less than n" was inconsistent with the 0 special case. Thanks for fixing this.

@dtolnaydtolnay assigned dtolnay and unassigned m-ou-seNov 18, 2021
@dtolnay

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Nov 18, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 17ce56f has been approved by dtolnay

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 18, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 18, 2021
…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`.
@ehuss

Copy link
Copy Markdown
Contributor

@bors r-

Failed in rollup: #91024 (comment)

Looks like this fails when run with overflow-checks enabled.

@borsbors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 19, 2021
@ehuss

Copy link
Copy Markdown
Contributor

The reason CI checks are green here is because overflow checks were added after this PR was submitted (in #89776).

@the8472
the8472force-pushed the advance_by-avoid-err-0 branch from 17ce56f to 04cecdfCompareNovember 19, 2021 11:35
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`.
@the8472
the8472force-pushed the advance_by-avoid-err-0 branch from 04cecdf to 3f9b26dCompareNovember 19, 2021 12:00
@the8472the8472 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 19, 2021
@dtolnay

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Nov 26, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 3f9b26d has been approved by dtolnay

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 26, 2021
@bors

bors commented Nov 27, 2021

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 3f9b26d with merge 5fd3a5c...

@bors

bors commented Nov 27, 2021

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: dtolnay
Pushing 5fd3a5c to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label Nov 27, 2021
@bors
bors merged commit 5fd3a5c into rust-lang:masterNov 27, 2021
@rustbotrustbot added this to the 1.59.0 milestone Nov 27, 2021
@rust-timer

Copy link
Copy Markdown
Collaborator

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

@the8472

Copy link
Copy Markdown
MemberAuthor

Thanks for all the reviews @dtolnay

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants

@the8472@rust-highfive@dtolnay@bors@ehuss@rust-timer@m-ou-se@JohnCSimon@rustbot