rust-lang / rust-lang/rust-clippy
Lint on slice literals i.e. `[...].to_vec()` and instead suggest `vec![]`
Open
@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
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.
Assessment
This issue has not been assessed yet.