Skip to content

Correct extract_if sample equivalent. #135734

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

Merged
merged 1 commit into from
May 5, 2025

Conversation

nk9
Copy link
Contributor

@nk9 nk9 commented Jan 19, 2025

Tracking issue: #43244

Original PR: #133265

The sample code marked as equivalent in the doc comment isn't currently equivalent. Given the same predicate and range, if your vector were [1, 2, 3, 3, 3, 3, 3, 3, 4, 5, 6], then all of the 3s would be removed. i is only incremented when an element is dropped, but range.end is unchanged, so the items shift down. I got very confused when reading the docs and trying to square this sample code with the explanation of how the function works.

Fortunately, the real extract_if() does not have this problem. I've added an end variable to align the behavior. I've also taken the opportunity to simplify the predicate, which now just matches odd numbers, and to pad out the vec of numbers to line up the zero-indexed range with the integers in the vec.

r? the8472

@rustbot
Copy link
Collaborator

rustbot commented Jan 19, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @the8472 (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 19, 2025
@nk9
Copy link
Contributor Author

nk9 commented Apr 7, 2025

Checking in on this. It would be nice if this could be fixed before extract_if is stabilized.

@tgross35 tgross35 assigned tgross35 and unassigned the8472 Apr 27, 2025
@tgross35
Copy link
Contributor

Thanks for the PR! Agreed that this should be updated, but I think it could be simplified a bit and we should be able to do a better assertion.

@tgross35 tgross35 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-review Status: Awaiting review from the assignee but also interested parties. labels Apr 27, 2025
@rustbot

This comment has been minimized.

@rustbot rustbot added the has-merge-commits PR has merge commits, merge with caution. label May 3, 2025
@nk9 nk9 force-pushed the extract_if-doc-equivalent branch from eb21a91 to 6a99ade Compare May 3, 2025 16:59
@rustbot rustbot removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. has-merge-commits PR has merge commits, merge with caution. labels May 3, 2025
@tgross35 tgross35 added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 3, 2025
@nk9 nk9 force-pushed the extract_if-doc-equivalent branch from 3fc83d2 to 215ab80 Compare May 4, 2025 20:21
@nk9
Copy link
Contributor Author

nk9 commented May 4, 2025

I've rebased and implemented the requested change. If there's anything else, please let me know! Oh, whoops, now I need to do the extract_if() comparison.

@nk9
Copy link
Contributor Author

nk9 commented May 4, 2025

Ooook, I think this is done now. Thanks for your guidance!

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Looks great! Please squash then should be good

Simpler predicate.
Compare sample code output to that of the library function.
@nk9 nk9 force-pushed the extract_if-doc-equivalent branch from fc42309 to 52d806a Compare May 4, 2025 22:43
@nk9
Copy link
Contributor Author

nk9 commented May 4, 2025

🟩 Hulk Squash! 🟩

@tgross35
Copy link
Contributor

tgross35 commented May 4, 2025

@bors r+ rollup

Fyi this may have a small conflict with #140625, you'll just have to rebase if that merges first and GH shows a conflict (we'll know in ~2.6 hours since that one is testing now).

@bors
Copy link
Collaborator

bors commented May 4, 2025

📌 Commit 52d806a has been approved by tgross35

It is now in the queue for this repository.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 4, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2025
Rollup of 4 pull requests

Successful merges:

 - rust-lang#135734 (Correct `extract_if` sample equivalent.)
 - rust-lang#140307 (Refactor rustc_on_unimplemented's filter parser)
 - rust-lang#140644 (Revert "Avoid unused clones in Cloned<I> and Copied<I>")
 - rust-lang#140648 (Update `compiler-builtins` to 0.1.157)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c44e1d6 into rust-lang:master May 5, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone May 5, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2025
Rollup merge of rust-lang#135734 - nk9:extract_if-doc-equivalent, r=tgross35

Correct `extract_if` sample equivalent.

Tracking issue: rust-lang#43244

Original PR: rust-lang#133265

The sample code marked as equivalent in the doc comment isn't currently equivalent. Given the same predicate and range, if your vector were `[1, 2, 3, 3, 3, 3, 3, 3, 4, 5, 6]`, then all of the 3s would be removed. `i` is only incremented when an element is dropped, but `range.end` is unchanged, so the items shift down. I got very confused when reading the docs and trying to square this sample code with the explanation of how the function works.

Fortunately, the real `extract_if()` does not have this problem. I've added an `end` variable to align the behavior. I've also taken the opportunity to simplify the predicate, which now just matches odd numbers, and to pad out the vec of numbers to line up the zero-indexed range with the integers in the vec.

r? the8472
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request May 11, 2025
…gross35

Correct `extract_if` sample equivalent.

Tracking issue: rust-lang#43244

Original PR: rust-lang#133265

The sample code marked as equivalent in the doc comment isn't currently equivalent. Given the same predicate and range, if your vector were `[1, 2, 3, 3, 3, 3, 3, 3, 4, 5, 6]`, then all of the 3s would be removed. `i` is only incremented when an element is dropped, but `range.end` is unchanged, so the items shift down. I got very confused when reading the docs and trying to square this sample code with the explanation of how the function works.

Fortunately, the real `extract_if()` does not have this problem. I've added an `end` variable to align the behavior. I've also taken the opportunity to simplify the predicate, which now just matches odd numbers, and to pad out the vec of numbers to line up the zero-indexed range with the integers in the vec.

r? the8472
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request May 11, 2025
Rollup of 4 pull requests

Successful merges:

 - rust-lang#135734 (Correct `extract_if` sample equivalent.)
 - rust-lang#140307 (Refactor rustc_on_unimplemented's filter parser)
 - rust-lang#140644 (Revert "Avoid unused clones in Cloned<I> and Copied<I>")
 - rust-lang#140648 (Update `compiler-builtins` to 0.1.157)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

5 participants