Open
Description
I tried this code (playground):
fn main() {
let r = 1.0;
let _ = r.sqrt();
let _ = r == 0_f32;
}
I expected rustc to infer the type of r as f32 based on the last line.
Instead, rustc failed to compile my program:
error[E0689]: can't call method `sqrt` on ambiguous numeric type `{float}`
--> src/main.rs:3:15
|
3 | let _ = r.sqrt();
| ^^^^
|
help: you must specify a type for this binding, like `f32`
|
2 | let r: f32 = 1.0;
| +++++
In most cases, type inference works both forwards and backwards, so why didn't it work here?
This is similar to #24124, but with an even stronger reason to feel the code should work. #99405 may also be related.