rust-lang / rust-lang/rust-clippy
new rule `unused_extract_if`
Open
Nobody has claimed this yet.
A-lint
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Many collections have the extract_if (previous named drain_filter) method. Sometimes the returned iterator ExtractIf are dropped directly. In such case, retain/retain_mut have better performance and readability.
Advantage
- Improve the performance
- Improve the readability
Drawbacks
No
Example
let mut v = vec![1, 2, 3, 4, 5];
let _ = v.extract_if(|&x| x % 2 == 0)
Could be written as:
let mut v = vec![1, 2, 3, 4, 5];
let _ = v.retain(|&x| x % 2 != 0)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing handling or lint tests for Rust's extract_if and retain methods. Implement the requested lint so discarded extract_if iterators are identified and the equivalent retain or retain_mut approach is suggested, then verify the example behavior with focused tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100