Skip to content

explicit_counter_loop false positive #3308

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

Closed
asomers opened this issue Oct 12, 2018 · 1 comment · Fixed by #3310
Closed

explicit_counter_loop false positive #3308

asomers opened this issue Oct 12, 2018 · 1 comment · Fixed by #3310

Comments

@asomers
Copy link

asomers commented Oct 12, 2018

The explicit_counter_loop lint wrongly detects that I'm using a variable as a loop counter. The code snippet is below.

        let mut skips = 0;
        for i in 0..k {
            while erasures.contains(i + skips) {
                skips += 1;
            }
            let row = i + skips;
            for j in 0..k {
                dec_matrix_inv[k * i + j] =
                    self.enc_matrix[k * row + j];
            }
        }

And Clippy suggests "fixing" it in a way that will clearly change its function:

warning: the variable `skips` is used as a loop counter. Consider using `for (skips, i
tem) in 0..k.enumerate()` or similar iterators
   --> src/common/raid.rs:216:18
    |
216 |         for i in 0..k {
    |                  ^^^^
    |
    = note: #[warn(clippy::explicit_counter_loop)] on by default
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#explicit_counter_loop

cargo +nightly clippy -V
clippy 0.0.212 (32b1d1f 2018-10-05)

@JoshMcguigan
Copy link
Contributor

Thanks for the report. I believe PR #3310 resolves this issue.

oli-obk added a commit that referenced this issue Oct 13, 2018
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue May 5, 2020
Changes:

````
fix for rustc master
mem_forget: fix syntax error in code sample
explicit_counter_loop fix rust-lang#3308 false positive
new_ret_no_self test remove tool lints cfg flag
Added new_ret_no_self exception to clippy to pass dogfood tests
Removed new_ret_no_self tests from method.rs
new_ret_no_self correctly lint impl return
Removed unused variables
new_ret_no_self fix false positive for impl trait return with associated type self
new_ret_no_self corrected panic and added test stderr
new_ret_no_self added positive test cases
Fix some more `stutter` warnings
unused unit lint
Install Windows SDK 10.0 on travis
cmp_owned refactor
cmp_owned correct error message if rhs is deref
Add a comment reminding to update README if the default changes
Specify which categories are enabled by default
Only run markdown linter on linux
Move Travis Windows build to allowed failures
Add Travis windows build
Fix `doc_markdown` lints
Fix `stutter` lints
Fix `similar_names` warnings
cmp_owned current suggestion for multiple deref
cmp_owned add test for multiple dereference
Corrected single-character string constant used as pattern found in dogfood test
Fixes 3289, cmp_owned wording and false positive
````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants