-
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
fix typo in numeric_arithmetic
logic
#13820
Conversation
You can probably build a test case which would fail before and succeed after your patch. For example, what if you define your own type, which implements multiplication by a floating point type? Since only the right hand site seems to be checked for floating points in binary operators, it might not trigger before your PR. It would be a great addition to make sure this bug does not reappear. Also, this would warrant a changelog entry since it appears that you are fixing a real bug. |
Float ops allowed only if both ops is float, otherwise there will be compile error, so this check almost redundant, i think? |
No, you can have different types for left side, right side and result. This would be valid: struct S;
impl std::ops::Mul<f32> for S {
type Output = f32;
fn mul(self, rhs: f32) -> Self::Output {
todo!()
}
}
fn test() -> f32 {
S * 3.0
} |
And by the way @klensy you can check the result of the You'll see that your PR causes some new triggers, and that they involve a non-floating point as a left operand, as in my example. |
And apart from missing tests, it looks good to me! |
Before it checked (erroneously) only right part of binop, now checks if both part is floats. Shouldn't it actually check if any part of binop is float instead? |
Detectable by #13828 |
Probably. |
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.
Looks like this regressed all the way back in rust-lang/rust@e97602e , where before it was checking for the same thing so this looks like the intended behavior to me. Thank you!
Wait,
I'll add follow up then. |
Looks like typo for me.
Looking at blame b76b0ae#diff-ac15e787d7d276b24f251f4f5bdedf1e6ac81aa1e2ea0db27219e9a7fa8b0b30L66 the same typo was before.
Is logic here actually correct? Tests passed locally, but i expected some changes.
changelog: none