Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Iterator::advance_by contract inconsistency #89916

Merged
merged 1 commit into from
Nov 27, 2021

Conversation

the8472
Copy link
Member

@the8472 the8472 commented Oct 15, 2021

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 the8472 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
Collaborator

r? @m-ou-se

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 15, 2021
@the8472 the8472 force-pushed the advance_by-avoid-err-0 branch from de31b95 to 17ce56f Compare October 15, 2021 15:48
@JohnCSimon JohnCSimon 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
Copy link
Member

@dtolnay dtolnay left a comment

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.

@dtolnay dtolnay assigned dtolnay and unassigned m-ou-se Nov 18, 2021
@dtolnay
Copy link
Member

dtolnay commented Nov 18, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Nov 18, 2021

📌 Commit 17ce56f has been approved by dtolnay

@bors bors 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
Contributor

ehuss commented Nov 19, 2021

@bors r-

Failed in rollup: #91024 (comment)

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

@bors bors 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
Contributor

ehuss commented Nov 19, 2021

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

@the8472 the8472 force-pushed the advance_by-avoid-err-0 branch from 17ce56f to 04cecdf Compare November 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 the8472 force-pushed the advance_by-avoid-err-0 branch from 04cecdf to 3f9b26d Compare November 19, 2021 12:00
@the8472 the8472 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
Member

dtolnay commented Nov 26, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Nov 26, 2021

📌 Commit 3f9b26d has been approved by dtolnay

@bors bors 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
Copy link
Contributor

bors commented Nov 27, 2021

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

@bors
Copy link
Contributor

bors commented Nov 27, 2021

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 27, 2021
@bors bors merged commit 5fd3a5c into rust-lang:master Nov 27, 2021
@rustbot rustbot added this to the 1.59.0 milestone Nov 27, 2021
@rust-timer
Copy link
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
Member Author

the8472 commented Nov 27, 2021

Thanks for all the reviews @dtolnay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant 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