-
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
Weird warning for needless_range_loop #398
Comments
cc @birkenfeld |
This only looks strange, but this lint doesn't check the range end expression at all. It only sees that you're indexing In this case, the iteratee could be |
SGTM |
@birkenfeld Well, I made the example simpler, but I my original code, both the Here is my example: fn levenshtein_distance(string1: &str, string2: &str) -> usize {
fn distance(i: usize, j: usize, d: &[Vec<usize>], string1: &str, string2: &str) -> usize {
match (i, j) {
(i, 0) => i,
(0, j) => j,
(i, j) => {
let delta =
if string1.chars().nth(i - 1) == string2.chars().nth(j - 1) {
0
}
else {
1
};
*[
d[i - 1][j] + 1,
d[i][j - 1] + 1,
d[i - 1][j - 1] + delta
].iter().min().unwrap()
},
}
}
let mut d = vec![];
for i in 0 .. string1.len() + 1 {
d.push(vec![]);
for j in 0 .. string2.len() + 1 {
let dist = distance(i, j, &d, string1, string2);
d[i].push(dist);
}
}
d[string1.len()][string2.len()]
}
for i in 0 .. string1.len() + 1 { but I could not iterate over the vector since it is empty. |
Is this a bug? |
Just adding onto this: I got this error for something along the lines of:
And this can't be replaced by a simple |
@Undeterminant do you know about |
@mccarton: I did not at the time, although the point was that the lint's suggestion of just using enumerate wasn't good enough. |
@Undeterminant this is possible to write with
I'm beginning to think that |
Agree. This lint doesn't seem to check what else you're doing with the range variable in the loop. While it can be replaced by using Simple example:
vs
2nd is needlessly more verbose. |
Hello.
I found a weird warning for a range loop.
In the following code:
I get the following warning:
This is wrong since I am iterating over the
string
, not thevec
.If I remove the line using the
vec
, the warning is gone.Thanks to fix this issue.
(By the way, is there an option to span errors instead of warnings in clippy?)
The text was updated successfully, but these errors were encountered: