rust-lang / rust-lang/rust-clippy
suggest iterator.take() instead of .enumerate() with comparison and break
Open
Nobody has claimed this yet.
A-lint
C-enhancement
L-complexity
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
let x = vec![0,1,2,3,4,5,6,7,8];
let limit: usize = 4;
for (count,data) in x.into_iter().enumerate() {
if count == limit {
break
}
println!("{}", data);
}
Instead, iterator.take() could be used which looks much nicer
let x = vec![0,1,2,3,4,5,6,7,8];
let limit: usize = 4;
x.into_iter().take(limit).for_each(|data| println!("{}", data));
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
Use the issue's two Rust examples as the behavioral specification, then locate the existing Clippy iterator-lint implementations and their tests. The work is done when the pattern using enumerate(), a comparison, and break receives a take() suggestion, with tests covering the shown limit behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100