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

Document the order of {Vec,VecDeque,String}::retain #60396

Merged
merged 2 commits into from
May 12, 2019

Conversation

cuviper
Copy link
Member

@cuviper cuviper commented Apr 30, 2019

It's natural for retain to work in order from beginning to end, but
this wasn't actually documented to be the case. If we actually promise
this, then the caller can do useful things like track the index of each
element being tested, as discussed in the forum. This is now
documented for Vec, VecDeque, and String.

HashMap and HashSet also have retain, and the hashbrown
implementation does happen to use a plain iter() order too, but it's
not certain that this should always be the case for these types.

r? @scottmcm

It's natural for `retain` to work in order from beginning to end, but
this wasn't actually documented to be the case. If we actually promise
this, then the caller can do useful things like track the index of each
element being tested, as [discussed in the forum][1]. This is now
documented for `Vec`, `VecDeque`, and `String`.

[1]: https://users.rust-lang.org/t/vec-retain-by-index/27697

`HashMap` and `HashSet` also have `retain`, and the `hashbrown`
implementation does happen to use a plain `iter()` order too, but it's
not certain that this should always be the case for these types.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 30, 2019
@scottmcm
Copy link
Member

@rust-lang/libs Was this a part of the expected contract, which just wasn't documented, or does it need an explicit team decision that this is the desired semantic?

Personally it seems reasonable to me; I don't see a good reason to ever do something different for Vec or String. (I could imagine VecDeque doing its two slices differently, one forward and one backward, but that wouldn't improve overall complexity, so probably wouldn't be worth the difference.)

@scottmcm scottmcm added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Apr 30, 2019
@alexcrichton
Copy link
Member

Let's find out...

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Apr 30, 2019

Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Apr 30, 2019
@rfcbot
Copy link

rfcbot commented May 1, 2019

🔔 This is now entering its final comment period, as per the review above. 🔔

@scottmcm
Copy link
Member

scottmcm commented May 9, 2019

@cuviper The comment changes here look good to me; want to also add some tests for this while we wait for the FCP to complete? From the quick look I did, the tests/examples don't see to exercise the FnMut-ness, nor check the order.

@cuviper
Copy link
Member Author

cuviper commented May 11, 2019

OK, I've added an ordered example to each.

@rfcbot
Copy link

rfcbot commented May 11, 2019

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels May 11, 2019
@scottmcm
Copy link
Member

Thanks, @cuviper!

@bors r+

@bors
Copy link
Contributor

bors commented May 12, 2019

📌 Commit 0545375 has been approved by scottmcm

@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 May 12, 2019
@bors
Copy link
Contributor

bors commented May 12, 2019

⌛ Testing commit 0545375 with merge 16e356e...

bors added a commit that referenced this pull request May 12, 2019
Document the order of {Vec,VecDeque,String}::retain

It's natural for `retain` to work in order from beginning to end, but
this wasn't actually documented to be the case. If we actually promise
this, then the caller can do useful things like track the index of each
element being tested, as [discussed in the forum][1]. This is now
documented for `Vec`, `VecDeque`, and `String`.

[1]: https://users.rust-lang.org/t/vec-retain-by-index/27697

`HashMap` and `HashSet` also have `retain`, and the `hashbrown`
implementation does happen to use a plain `iter()` order too, but it's
not certain that this should always be the case for these types.

r? @scottmcm
@bors
Copy link
Contributor

bors commented May 12, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: scottmcm
Pushing 16e356e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 12, 2019
@bors bors merged commit 0545375 into rust-lang:master May 12, 2019
@cuviper cuviper deleted the ordered-retain branch May 17, 2019 21:49
@breezewish
Copy link

I believe unit tests to ensure the retain order is missing:

fn test_retain() {

@cuviper
Copy link
Member Author

cuviper commented Jun 17, 2019

I think the doc tests suffice, but you could add more standalone tests if you like.

cuviper added a commit to cuviper/rust that referenced this pull request Jul 28, 2021
The examples added in rust-lang#60396 used a "clever" post-increment hack,
unrelated to the actual point of the examples. That hack was found
[confusing] in the users forum, and rust-lang#81811 already changed the `Vec`
example to use a more direct iterator. This commit changes `String` and
`VecDeque` in the same way for consistency.

[confusing]: https://users.rust-lang.org/t/help-understand-strange-expression/62858
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 30, 2021
…lett

Update the examples in `String` and `VecDeque::retain`

The examples added in rust-lang#60396 used a "clever" post-increment hack,
unrelated to the actual point of the examples. That hack was found
[confusing] in the users forum, and rust-lang#81811 already changed the `Vec`
example to use a more direct iterator. This commit changes `String` and
`VecDeque` in the same way for consistency.

[confusing]: https://users.rust-lang.org/t/help-understand-strange-expression/62858
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. 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-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants