rust-lang / rust-lang/rust-clippy
complexity: use `extend` instead of `append`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Collections (BinaryHeap, BTreeMap, BTreeSet, LinkedList, VecDeque, Vec) can be grown with both append and extend:
things.append(&mut more_things);
things.extend(more_things);
This can be applied in case more_things isn't re-used later (extend consumes more_things), things has an impl Extend and more_things has an impl IntoIterator.
Advantage
- less cognitive complexity, because you don't need the
&mutborrow - it's shorter 😅
Drawbacks
I don't know if there is overhead / a performance impact of using extend instead of append.
Example
things.append(&mut more_things);
Could be written as:
things.extend(more_things);
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 from the Rust examples in the issue and identify the Clippy lint entry point and relevant tests; no file or test paths are provided. Establish whether replacing append with extend is safe under the stated ownership and trait conditions, including any performance impact, and add coverage showing the intended cases are reported.
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