sort + indexing => select_nth_unstable
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by checking how rust-clippy currently recognizes a sort or sort_unstable followed by indexing. Compare the median example with select_nth_unstable and define conservative boundaries that avoid false positives. Done means the intended pattern receives a clear suggestion without triggering on uncertain cases.
Written by the indexing model from the issue text.
Description
What it does
This pedantic lint is supposed to suggest replacing a sort or sort_unstable followed by an indexing, with the usage of a more efficient select_nth_unstable. I am not sure if this lint is too much specialized, if you think it's it, then close down this issue.
Advantage
Faster, slightly more clear purpose of the code.
Drawbacks
It's hard to spot the cases where this lint should fire. So better to keep it conservative and avoid most false positives.
Example
#[must_use]
pub fn compute_median(data: &[u32]) -> u32 {
let mut data_sorted = data.to_owned();
data_sorted.sort_unstable();
data_sorted[data_sorted.len() / 2]
}
The link should suggest to use instead:
select_nth_unstable()
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
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.
More from rust-lang/rust-clippy
-
C-bug L-suggestion
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
rust-lang/rust-clippy#17674 · 5 comments ·
-
C-bug L-suggestion
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-clippy#17673 · 3 comments ·
-
C-bug I-false-positive
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
rust-lang/rust-clippy#17566 ·
-
A-documentation
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
rust-lang/rust-clippy#17259 · 3 comments ·
-
A-documentation A-website C-bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
rust-lang/rust-clippy#16981 · 1 reaction ·
All issues in rust-lang/rust-clippy
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
kwakseongjae/auto-hwp#319 ·
-
area:cli bug filter-quality good first issue priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bevyengine/bevy#25861 ·
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
enhancement remote
Difficulty 2/5 1-3 hours Newbie friendliness 68/100