-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
False positive on while_let_on_iterator with nested while let #600
Comments
The error in question is:
The problem with trying to make either of those instances a for loop is that this would move the iterator into the loop. So I guess to fix this, we'll have to make sure that the iterator isn't used anywhere within the loop (and also mark used iterators so the inner loop will not be reported either). |
jup, encountered this as well with this design. i don’t like this at all but have no idea how to make it prettier. the idea is to find the pair of positions that points to the _n_th newline in both buffers let mut b1it = b1.iter().enumerate();
let mut b2it = b2.iter().enumerate();
let mut chunk_ends = (0, 0);
loop {
let mut new_chunk_end1 = 0; let mut c1 = 0;
while let Some((pos, byte)) = b1it.next() {
if *byte == b'\n' {
c1 += 1;
if c1 == 4 {
new_chunk_end1 = pos + 1;
break;
}
}
}
let mut new_chunk_end2 = 0; let mut c2 = 0;
while let Some((pos, byte)) = b2it.next() {
if *byte == b'\n' {
c2 += 1;
if c2 == 4 {
new_chunk_end2 = pos + 1;
break;
}
}
}
// if we found a whole new chunk in both
if c1 == 4 && c2 == 4 {
chunk_ends = (new_chunk_end1, new_chunk_end2);
} else {
break;
}
}
do_stuff_with(&b1[0..chunk_ends.0], &b2[0..chunk_ends.1]) |
can't you just do a for loop that iterates over a |
ugh, true, yeah! my code is still ugly there, but that part is prettier now 😄 |
This is not linted anymore: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a856a012f8a5c1564e9eb2c87caab9b7 We also have tests for nested loops: rust-clippy/tests/ui/while_let_on_iterator.rs Line 137 in 896d82f
I'm going to go ahead and close this issue. |
Clap exhibits what seems to be a false positive on while_let_on_iterator because it has a nested while let on the same iterator.
The text was updated successfully, but these errors were encountered: