Skip to content

needless_range_loop triggering on collections created inside loop #601

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
AtheMathmo opened this issue Jan 30, 2016 · 0 comments
Closed

Comments

@AtheMathmo
Copy link
Contributor

I have some code like this:

for i in 0..10 {
    let mut id_col = vec![0f64; 10];
    id_col[i] = 1f64;
    // Do something with my id_col...
}        

This triggers the needless_range_loop:

warning: the loop variable i is only used to index id_col. Consider using for item in id_col.iter().take(self.rows) or similar iterators, #[warn(needless_range_loop)] on by default

But id_col does not exist outside of the loop.

I'm sure the code is terribly inefficient and I'd love a better way to do it but I think the lint isn't behaving correctly here.

Note: I edited the above example. In my original source code I'm using generics - I assume that won't make a difference.

@mcarton mcarton mentioned this issue Feb 13, 2016
llogiq added a commit that referenced this issue Feb 14, 2016
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

No branches or pull requests

1 participant