-
Notifications
You must be signed in to change notification settings - Fork 1.6k
reversed_empty_ranges false positive #5808
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
Comments
TIL, Rust has negative indices in ranges 😮 cc @ebroto |
How can I try and reproduce this bug? |
I just tested in a real project and I do see the |
Okay, I'll give this a shot. |
As per the discussion in the #clippy channel, the best way to fix this would be to add a check for whether the range is inside a macro. |
So...I kinda failed hard on this one. Hopefully, someone else picks it up. |
I've been looking into this, but it seems the fix is not as simple as it seemed in the discussion. In the ndarray example, the ranges are used as macro arguments and used as-is in the macro body, so they don't strictly come from an expansion and the macro checks don't work. I don't know of an alternative approach. I'm thinking about constraining this lint to contexts where the range literal is directly used in a method call to an iterator method (besides slice indexing and for loop iteration). I think that is relatively simple to do, but would left out cases like the following: let r = (10..0);
r.for_each(...); I believe trying to follow the local is error prone, especially if we don't want to use MIR. Should I go for constraining the lint, or are there other solutions that I'm not aware? |
As a user of ndarray, I can use negative indexing in slices, like I would do with NumPy
Since Rust 1.45.0, I get this error when I run clippy:
error: this range is empty so it will yield no values
. This message is wrong: my code compiles and runs as intended. Clippy shouldn't only check ifend <= start
, it should also check ifend
is negative, or if it's aisize
slice.The text was updated successfully, but these errors were encountered: