-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Confusing error message when using arithmetic operators on different number types #27604
Comments
This's because type system of Rust is strict, and there isn't generic typeclass similar Num in Haskell with rules to coercions. But it's not bad, because implicit bugs give large problems in system programming, statistics and medical computations. fn main() {
let x : f32 = 1.0;
let _y = x / 10 as f32;
} Maybe in the future releases Rust can recognize more complex relation cases like yours. |
Hi, I think Rust's strict type system is awesome and I'm not complaining about that. I'm saying that the error message is bad because it doesn't tell the user what the actual problem is (which is that they are trying to perform operations on two different number types). I knew that Rust doesn't implicitly convert numbers but I was still briefly confused when I got this particular error from the compiler. I imagine a new user would be lost and would have to turn to StackOverflow or the user forms to figure out how to fix the error. Giving the user one of these errors instead would let them easily understand what's going on:
or better yet
|
The problem is that you are dealing with integer literal variables (they can be inferred into an integer of unknown signedness and size - If you provided the literal's type, you would get an error like:
|
@arielb1 Thanks for the info! I just wanted to raise the issue because it seems like performing these kinds of operations on numbers is something a beginner is likely to do and if they try to do something like I did, the error message can be confusing. |
I think this is a duplicate of #24770. |
The error message is confusing because it reads as though you cannot divide
f32
s at all when the real issue is that you can't divide af32
by any other numeric type. The error message should at least say something about the different numeric types involved. Ideally it would suggest changing10
to10.0
or casting the term.The text was updated successfully, but these errors were encountered: