-
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
Float comparison lint doesn't seem to trigger on float array comparison #4277
Comments
Hi, I would like to take a look at this. |
Great! If you have any questions, don't hesitate to ask. |
Cool, I am going to go through it and make sure to reach out. :) |
You're on the right track. In the line you linked is a check for the left and right side of the Eq/Ne Binop if both sides are floats: rust-clippy/clippy_lints/src/misc.rs Lines 521 to 523 in e7d153a
This function takes the expression, "derefs" it, and checks if the type is float. (i.e Hope this helps :) |
Yes, this definitely helps. I think I can work with this. Thanks! |
Hey @flip1995. I've been caught up with work and this slipped under my radar; apologies for not giving an update sooner. I'd be happy to let someone else finish this if there's someone that you might recommend. If not, I'd still be interested in completing the feature. 😃 |
No problem, you can get back to it, once you have more time 👍 |
Thanks for understanding :) |
Hi, I'd like to take up this issue if possible. |
Yeah sure, you can take a look at #4343 for some inspiration. |
Hey @Toxyxer. Go right ahead. I'm interested in seeing the solution that you come up with! |
Hey @flip1995, I've opened a pull request with my proposed changes. Some comments: I think this example should trigger the lint because the arrays are declared with let x = 0.0;
let y = 0.0;
x == y; triggers the lint. I've changed the code so that when we change the code in the example to declare arrays with I've noticed that the
so I didn't use it in tests. It's a separate issue so I didn't do anything about it. It's already reported here: #3804. I'm new to rust so there is probably room for improvement in the submitted code. Thanks in advance for any suggestions on how to make it better. |
…comparison, r=flip1995 Add lint for float in array comparison Fixes rust-lang#4277 changelog: - Added new handler for expression of index kind (e.g. `arr[i]`). It returns a constant when both array and index are constant, or when the array is constant and all values are equal. - Trigger float_cmp and float_cmp_const lint when comparing arrays. Allow for comparison when one of the arrays contains only zeros or infinities. - Added appropriate tests for such cases.
… r=flip1995 Add lint for float in array comparison Fixes #4277 changelog: - Added new handler for expression of index kind (e.g. `arr[i]`). It returns a constant when both array and index are constant, or when the array is constant and all values are equal. - Trigger float_cmp and float_cmp_const lint when comparing arrays. Allow for comparison when one of the arrays contains only zeros or infinities. - Added appropriate tests for such cases.
… r=flip1995 Add lint for float in array comparison Fixes #4277 changelog: - Added new handler for expression of index kind (e.g. `arr[i]`). It returns a constant when both array and index are constant, or when the array is constant and all values are equal. - Trigger float_cmp and float_cmp_const lint when comparing arrays. Allow for comparison when one of the arrays contains only zeros or infinities. - Added appropriate tests for such cases.
the second assert triggers clippy, the first doesn't.
The text was updated successfully, but these errors were encountered: