rust-lang / rust-lang/rust-clippy
new lint: `endless_iter`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
-
We can create an endless Iterator easily by calling the
Iterator::cycle()method or by Range literal construction without an upper bound.
There is a corner case; thecyclecall on an empty iterator will not create an endless iterator. -
The endless property will be passed by many methods without an early return branch, e.g.:
- map
- filter
- skip
- skip_while
- map_while
- zip_longest
- ...
- We also have some finalizers that will not early return:
- min
- max
- last
- count
- for_each
- reduce
- collect *
- sum *
- product *
- ...
There are also some false negative cases because FromIter, Sum and Product are customizable, so there may be some early-return implementation.
We can detect such cases.
Another acceptable name for the lint is infinite_iter, both are good.
Lint Name
endless_iter
Category
correctness
Advantage
Avoid some endless loops
Drawbacks
Some false negative cases
Example
(1..).map(|x| x + 2).for_each(|x| dbg!(x))
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 with the Rust example and the listed iterator methods and finalizers; done means the new correctness lint detects applicable endless iterator chains while accounting for the documented false negatives.
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
- 35/100