rust-lang / rust-lang/rust-clippy
Warn if make iterator out of iterator in `for`.
Open
Nobody has claimed this yet.
C-enhancement
E-medium
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Hi.
fn main() {
// for m in (1..10).take(5) is enough!
for m in (1..10).take(5).collect::<Vec<i32>>() {
println!("{}", m);
}
}
.take(5) gives iterator that is usable in for loop.
.collect::<Vec<i32>>() creates Vec from .take iterator and it(Vec) has iterator behaviour too.
What about creating lint, that warns, because code creates iterator out of iterator unnecessarily?
Thanks.
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 files, tests, or entry points. Start from the Rust example in the report and inspect existing iterator-related lints in rust-clippy; done means a lint warns when a collected iterator is immediately used in a for loop, with coverage for the reported pattern.
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
- 25/100