rust-lang / rust-lang/rust-clippy

Lint on slice literals i.e. `[...].to_vec()` and instead suggest `vec![]`

Open
#17,478 1 comment 0 reactions 1 assignee View on GitHub

@DanielEScherzer is already working on this.

Since Jul 31, 2026.

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

Description

What it does

If one writes a slice literal immediately followed by to_vec(), e.g. [1, 2, 3].to_vec() one should just write vec![1, 2, 3].

Advantage

Code looks nicer / less awkward.

Drawbacks

As far as I can tell, none.

Example
[1, 2, 3, 4, 5].to_vec()

Could be written as:

vec![1, 2, 3, 4, 5]
Comparison with existing lints

I don't see any particularly relevant.

Only maybe would be clippy::slow_vector_initialization but I suspect the compiler optimises this anyway, also clippy::vec_init_then_push.

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.