rust-lang / rust-lang/rust-clippy
vec -> array lint for simple cases
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
In many blog posts online I see code like:
fn main() {
let a = vec![10, 20, 30];
let tot: u32 = a.iter().sum();
println!("Total: {}", tot);
}
I'd like a Clippy lint that suggests to write instead:
fn main() {
let a = [10, 20, 30];
let tot: u32 = a.iter().sum();
println!("Total: {}", tot);
}
That is, to suggest to use arrays in simple cases where dynamic arrays aren't necessary. Even if such lint is very conservative it's still going to be useful to teach inexperienced Rust programmers to avoid heap allocations (Clippy is also a learning tool today). Rust programmers later could remember the idea and generalize it.
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
The issue names no implementation files, tests, or entry points. Start by locating Clippy's lint and test conventions, then define conservative cases based on the vec! and array examples; done means those simple cases receive a tested suggestion without affecting cases that need dynamic allocation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100