-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Bad "Ambiguous Numeric Type" Recommendation from Compiler in for loop #53572
Comments
If rust-lang/rfcs#2522 is accepted, the suggestion should work as is. |
Beside rfc2522, it's better to minimize the usages of as casts, so this is better:
|
Is there a reason to avoid Given there is a good workaround and a forthcoming change, should this issue stay open or be closed? This is my first github issue and second week using Rust. |
@spwitt: this issue can stay open! This is currently a valid issue with the diagnostics: it might just be worth waiting for the RFC (or making a temporary fix now).
In this example, no: all |
The incorrect suggestion is "fixed" in nightly since #51670:
Casting ( |
@varkor I'm inclined to close this as duplicate of #51972 and #51634, but we probably should still improve the output to be
cc @zackmdavis who proposed that in one of the linked tickets. |
The use of "as" should be minimized in Rust code because Rust doesn't perform overflow tests for "as" casts even in debug builds. It's a significant Rust design mistake. |
It is a bit off topic, but is it intended that compiler is unable to infer integer type from method usage? |
Issue is still valid |
Current output:
|
The
pow
function cannot be called on an ambiguous numeric type. Ifpow
is called on the variable of afor
loop, the compiler's recommended solution to add a concrete numeric type does not compile.Example code with ambiguous numeric type:
Gives the error:
Implementing this recommendation by adding type to variable
i
as shown in the compiler recommendation and trying to compile again gives the error:Not sure if there is a better solution, but adding a cast to the range rather than specifying the type of the variable worked for me:
The text was updated successfully, but these errors were encountered: