rust-lang / rust-lang/rust-clippy
Improve suggestions for same_item_push lint
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
The suggestion to use resize() is not optimal because it needs calculation of the difference between current size of the collection and the desired size. The suggestion to use vec![] is not great because it will generally require an extra allocation. Instead, I've landed upon this solution. Maybe it could be suggested:
- for _ in 0..forward {
- self.buffer.push(255);
- }
+ self.buffer.extend(std::iter::repeat(255).take(forward));
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
Begin by locating the same_item_push lint entry point and its diagnostic tests. Compare the existing resize() and vec![] suggestions with the proposed extend/repeat/take form, then update the recommendation and verify the lint tests show the intended suggestion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100