Lint for unbounded iterations checking#17242
Draft
PLeVasseur wants to merge 1 commit into
Draft
Conversation
llogiq
reviewed
Jun 14, 2026
| ExprKind::Block(block, _) => block.expr.as_ref().map_or(Bounded, |e| is_unbounded(cx, e)), | ||
| ExprKind::AddrOf(BorrowKind::Ref, _, e) => is_unbounded(cx, e), | ||
| ExprKind::Struct(..) => higher::Range::hir(cx, expr).is_some_and(|r| r.end.is_some()).into(), | ||
| _ => Bounded, |
Contributor
There was a problem hiding this comment.
We should have a comment explaining that other expression kinds don't fit the lint, therefore we mark it as bounded to avoid fiurther calculation
| is_unbounded(cx, receiver).and(is_unbounded(cx, &args[0])) | ||
| } else if method.ident.name == sym::chain { | ||
| is_unbounded(cx, receiver).or(is_unbounded(cx, &args[0])) | ||
| } else { |
Contributor
There was a problem hiding this comment.
flat_map and flatten should always be ``Unbounded`.
Also take should always be Bounded
|
|
||
| fn main() { | ||
| (0..).all(|x| x > 0); | ||
| //~^ unbounded_iter |
Contributor
There was a problem hiding this comment.
We want a lot more test cases, both positive and negative ones.
For each case in our is_unbounded function I'd like to have at least one test case.
I'd also like to see method calls like .max(), .sum() and .collect() to see which part of the expression gets linted (we may want to have special handling for those).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you for making Clippy better!
We're collecting our changelog from pull request descriptions.
If your PR only includes internal changes, you can just write
changelog: none. Otherwise, please write a short commentexplaining your change.
It's also helpful for us that the lint name is put within backticks (
` `),and then encapsulated by square brackets (
[]), for example:If your PR fixes an issue, you can add
fixes #issue_numberinto thisPR description. This way the issue will be automatically closed when
your PR is merged.
If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.
.stderrfile)cargo testpasses locallycargo dev update_lintscargo dev fmtNote that you can skip the above if you are just opening a WIP PR in
order to get feedback.
Delete this line and everything above before opening your PR.
Please write a short comment explaining your change (or "none" for internal only changes)
@llogiq last month at RustWeek 2026 was walking me through the "how" of writing a Clippy lint.
Life got a little busy, but he suggested that I open this as a WIP for now so that I can get a little feedback and then keep chipping away at it =]
changelog: