1

This program does not compile: "type annotations needed".

fn main() {
    let sum = [0,1,2,3].iter().sum();
    println!("{}", sum);
}

Even if I change the line to:

let sum = [0i32,1,2,3].iter().sum();

not even this:

let vec: [i32; 4] = [0,1,2,3];
let sum = vec.iter().sum();

Why the compiler can not do type inference? Isn't it obvious that i want a sum with type i32?

0 Answers0