rust-lang / rust-lang/rust-clippy

complexity: use `extend` instead of `append`

Open
#12,277 2 comments 1 reaction 0 assignees View on GitHub

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

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 &mut borrow
  • 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.