-
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
Add a lint for when ranges are used inside of a Vec #10932
Comments
@zkldi @anden3 and @arvsrn helped me figure this out while I came across this issue on Rustlings (primitive_ types3), they may be able to improve this suggestion some. And yes, I know this isn't how I was supposed to do the exercise, but now I found a lint that can be added to improve the UX :) |
There are many cases where a @rustbot claim |
similarly, |
I've run into this lint firing a fair amount for code that deals with |
Its main use case is the demonstrative example, where there are no type annotations and no clear indication that it's a range. There are many cases where |
Surely this would become obvious once you came to use the Vec? I dunno, it feels odd to me that a lint would be enabled by default that is so susceptible to false positives? |
The important part of |
Ah, this unfortunately got into stable already. For now just disable the lint in larger codebases, hopefully there will either be a coincidental point release or the fix will get into 1.73.0. |
What it does
When someone goes to put a range inside of a Vec, Clippy should probably check with them to make sure that's what they actually want to do. They may want to go over the range and collect that all into a Vec.
Advantage
vec![0..100]
doesn't work.Drawbacks
None AFAIK, aside from needing to disable it for valid use cases.
Example
You may want to make a Vec of integers, with the length specified here, not a Vec of ranges. Here are some potential solutions:
Alternatively, you may want to make an Array instead, with each value initialized to 0:
The text was updated successfully, but these errors were encountered: