This does not compile, complaining that the type parameter for sum() is not known. But why can it not be infered? Can it possibly be anything other than f64?
fn main() {
let x: f64 = 1.0;
let y: f64 = 2.0;
let z: f64 = 3.0;
let sum: f64 = x + vec![y, z].iter().sum();
println!("Sum is {sum}");
}
Compiling playground v0.0.1 (/playground)
error[E0284]: type annotations needed
> src/main.rs:5:42

5  let sum: f64 = x + vec![y, z].iter().sum();
  ^^^ cannot infer type of the type parameter `S` declared on the method `sum`
 
 type must be known at this point

= note: cannot satisfy `<f64 as Add<_>>::Output == f64`
help: consider specifying the generic argument

5  let sum: f64 = x + vec![y, z].iter().sum::<S>();
 +++++
For more information about this error, try `rustc explain E0284`.
error: could not compile `playground` (bin "playground") due to previous error
You can easily conclude that the answer is "yes" if you look at the signature of Iterator::sum(). It's a generic, so it can be anything that impls Sum<f64>.
Thank you! Fascinating. I suppose a realistic example for such a type A would be complex numbers.
OK, so I understand it could be some other type in general. But no such type is in scope in my example, so it can only be f64, or can it? Is type inference being conservative here to prevent breaking in case such a type is added? Or would type inference become too costly if it inferred examples like this?