rust-lang / rust-lang/rust-clippy

Prefer `Vec::extend_from_slice` over `Vec::extend` with `slice::to_vec`

Open
#16,725 1 comment 0 reactions 1 assignee View on GitHub

@borngraced is already working on this.

Since Mar 20, 2026.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

Replace vec.extend(slice.to_vec()) with vec.extend_from_slice(slice)

Advantage

Saves making an uneccessary Vec (with a heap allocation and all that comes with it), and I think the resulting code is clearer

Drawbacks

No response

Example
let mut items = vec![1, 2, 3];
let slice = &[4, 5, 6];
items.extend(slice.to_vec());

Could be written as:

let mut items = vec![1, 2, 3];
let slice = &[4, 5, 6];
items.extend_from_slice(slice);
Comparison with existing lints

This feels similar to redundant_clone, and it might be reasonable to fold this under that lint instead of making a new one? I don't have strong feelings either way, just that clippy should lint on this case somehow

Additional Context

No response

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.