Skip to content

Suggest retain_mut over retain as Vec::extract_if alternative #140625

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

Conversation

paolobarbolini
Copy link
Contributor

@paolobarbolini paolobarbolini commented May 3, 2025

The docs for Vec::extract_if suggest using Vec::retain if the user doesn't need the removed item. Given that extract_if gives a mutable reference to the evaluated element, retain_mut is the most appropriate alternative, not retain.

@rustbot
Copy link
Collaborator

rustbot commented May 3, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 May 3, 2025
@paolobarbolini paolobarbolini force-pushed the vec-extract-if-alt-is-retain_mut branch from a8ae11a to 5cbb27f Compare May 3, 2025 16:39
@Mark-Simulacrum
Copy link
Member

@bors r+ rollup

Seems fine, though not a strong opinion in either direction.

@bors
Copy link
Collaborator

bors commented May 4, 2025

📌 Commit 5cbb27f has been approved by Mark-Simulacrum

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-review Status: Awaiting review from the assignee but also interested parties. labels May 4, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 4, 2025
Rollup of 6 pull requests

Successful merges:

 - rust-lang#137280 (stabilize ptr::swap_nonoverlapping in const)
 - rust-lang#140457 (Use target-cpu=z13 on s390x codegen const vector test)
 - rust-lang#140619 (Small adjustments to `check_attribute_safety` to make the logic more obvious)
 - rust-lang#140625 (Suggest `retain_mut` over `retain` as `Vec::extract_if` alternative)
 - rust-lang#140627 (Allow linking rustc and rustdoc against the same single tracing crate)
 - rust-lang#140630 (Async drop source info fix for proxy-drop-coroutine)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 760d8da 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#140625 - paolobarbolini:vec-extract-if-alt-is-retain_mut, r=Mark-Simulacrum

Suggest `retain_mut` over `retain` as `Vec::extract_if` alternative

The docs for `Vec::extract_if` suggest using `Vec::retain` if the user doesn't need the removed item. Given that `extract_if` gives a mutable reference to the evaluated element, `retain_mut` is the most appropriate alternative, not `retain`.
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.

4 participants