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
skip float_cmp check if lhs is a custom type #11385
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @blyxyas (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
This would fail if the You can check this example for reference, we should also add a test where the |
Not sure I understand this correctly, we already checked that lhs is a float before we enter the lint, if lhs doesn't implement PartialEq, nothing should happen. Before this pr lint will be performed if either lhs or rhs is float |
Oh I get it now! If the second value doesn't implement PartialEq, it will have a compiler error before linting. Right? |
Yes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I think this is good then ❤️.
Could you squash these 2 commits into a single one?
meow 🐱 |
allow float_cmp with lhs is a custom type *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: [`float_cmp`]: allow float eq comparison when lhs is a custom type that implements PartialEq<f32/f64> If the lhs of a comparison is not float, it means there is a user implemented PartialEq, and the caller is invoking that custom version of `==`, instead of the default floating point equal comparison. People may wrap f32 with a struct (say `MyF32`) and implement its PartialEq that will do the `is_close()` check, so that `MyF32` can be compared with either f32 or `MyF32`.
@bors r- I just noticed, this should account for cases where the custom type isn't on the right side, but also if it only on the left side. And that is exactly what the original code did. It checked if either the lhs or the rhs are floats, it isn't a |
☀️ Try build successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
@blyxyas I think this pr might caused some confusion due to a previous typo in the title. Anyway, my motivation is this: in a project I'm working on, we use a custom type to wrap f64 to add some functionality, which include a |
I'll do some more testing on this patch. I'm not sure it really is caused because of this |
Mmmmmm... I just checked it, it does change the logic. I find it pretty weird that this inclusive operator changes the outcome in exclusive-like behaviours. LGTM! Thanks ❤️ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Please write a short comment explaining your change (or "none" for internal only changes)
changelog: [
float_cmp
]: allow float eq comparison when lhs is a custom type that implements PartialEq<f32/f64>If the lhs of a comparison is not float, it means there is a user implemented PartialEq, and the caller is invoking that custom version of
==
, instead of the default floating point equal comparison.People may wrap f32 with a struct (say
MyF32
) and implement its PartialEq that will do theis_close()
check, so thatMyF32
can be compared with either f32 orMyF32
.