rust-lang / rust-lang/rust-clippy

Improve suggestions for same_item_push lint

Open
#6,156 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement L-suggestion
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.