Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mutate_range_bound on immediately continued outer loop #13870

Open
Hoetty opened this issue Dec 23, 2024 · 0 comments
Open

mutate_range_bound on immediately continued outer loop #13870

Hoetty opened this issue Dec 23, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Hoetty
Copy link

Hoetty commented Dec 23, 2024

Summary

When mutating a variable, that serves as a range bound for an outer loop, but then immediately continuing a loop even further up, a warning of type mutate_range_bound is still emitted, even though the affected loop will be exited, similar to using a break.

This behavior is similar to that described in the issue #7532

Lint Name

mutate_range_bound

Reproducer

I tried this code:

let mut collection = [4, 3, 2, 1];
    let mut i = 0;
    'outer: while i < collection.len() {
        for j in 0..i {
            if collection[j] > collection[i] {
                collection.swap(j, i);
                i -= 1;
                continue 'outer;
            }
        }

        i += 1;
    }

I saw this happen:

warning: attempt to mutate range bound within loop
   --> src/main.rs:133:17
    |
133 |                 i -= 1;
    |                 ^
    |
    = note: the range of the loop is unchanged
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mut_range_bound

I expected to see this happen:
No warning should be emitted, as the affected loop is immediately exited by continuing the outer loop.

Version

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1

Additional Labels

No response

@Hoetty Hoetty added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

1 participant