-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Silent failure for empty range #54204
Comments
But it does bark at you:
|
Hmmm, you're right! I guess I ran into this within a macro I'm working on so I just don't get some of the compiler stuffs in that case. Must have missed the waring the first time I ran the example outside of a macro. Thanks! I realized after writing this issue that I also meant to include the example below which does not complain:
Obviously it's a ridiculous scenario so probably not worth covering but to me Either way, thanks for the quick follow up 😸 |
Agree that we should probably add an "empty range" lint for cases like |
Related: #47213 |
This is covered by Clippy's |
Then we can safely close this ticket, as it will be handled by the clippy one. |
I've just run into an issue where with trying to for loop over a range where the upper bound is one above the MAX of the primitive represented by i as shown below:
// i is u8
for i in 0..256 {...}
I understand that in this particular case 0 and 256 are the same, meaning that the range
0..0
and0..256
with regard to u8 are the same. Part of the issue in my opinion is that I'd argue that the above code is also equivalent to the below code:// i is u8
for i in 0..=255 {...}
I definitely understand the argument that they aren't so to be fair, if the first example can/will not be supported that's totally reasonable seeing as 256 is outside of the range of a u8.
However, I do think it's reasonable for the compiler to at least bark at you about the first example considering the loop and it's contained code are essentially dead/unreachable code.
My initial proposal would be to just have the compiler at least warn you about the unreachable nature of your code from example 1. My pie in the sky ask would be that the compiler would be smart enough to handle the first example, again though, I do understand why that might not be a popular ask.
The text was updated successfully, but these errors were encountered: