Closed
Description
The following code (playground):
for i in 0..100 {
println!("{}", i.pow(2));
}
fails to compile. The error message correctly points to the problem but the help message's suggestion is a syntax error:
error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}`
--> src/main.rs:3:26
|
3 | println!("{}", i.pow(2));
| ^^^
help: you must specify a type for this binding, like `i32`
|
2 | for i: i32 in 0..100 {
| ^^^^^^
Following the suggestion leads to another compile error (missing 'in' in for loop). Usually the correct solution in this case is to add the type to the range (0i32..100
).