Fix needless_range_loop false positive with nested indexing#17438
Open
XhesicaFrost wants to merge 1 commit into
Open
Fix needless_range_loop false positive with nested indexing#17438XhesicaFrost wants to merge 1 commit into
needless_range_loop false positive with nested indexing#17438XhesicaFrost wants to merge 1 commit into
Conversation
Collaborator
|
Thanks for the pull request, and welcome! You should hear from one of our reviewers after this PR gets at least 2 reviews from the community. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
XhesicaFrost
force-pushed
the
fix-17432-needless-range-loop
branch
from
July 21, 2026 13:35
7790ac9 to
1575048
Compare
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.
needless_range_loopcould emit an incorrect suggestion for nested indexingexpressions such as
a[sum % 5][i].In this case, the container indexed by the loop variable may change between
iterations, so replacing the range loop with an iterator over the base
container would change the program's semantics.
This detects non-constant container-selection indices while walking nested
index expressions and suppresses the lint in those cases. The existing behavior
is preserved when the loop variable selects the outer container.
A regression test for the reported case and a corresponding positive test have
been added.
fixes #17432
changelog: [
needless_range_loop]: avoid false positives when indexing dynamically selected nested containers