Rust performs type inference in fairly advanced situations. Could someone please explain (or point to) the rules that describe what can and cannot be inferred?
The first one is simple: The type of a binding is the type of the bound expression:
let n = 10u32;
// Same as:
// vvvvv
let n: u32 = 10u32;
This next one is more surprising to me: The generic parameter on the right is deduced from the binding type on the left:
let n: u32 = "10".parse().unwrap();
// same as: vvvvvvv
let n: u32 = "10".parse::<u32>().unwrap();
This also works for "member functions" of generic types:
let b = Box::new(10u32);
// same as:
// vvvvv vvvvvvv
let b: Box<u32> = Box::<u32>::new(10u32);
But the strangest of all is type inference across statements:
let v = Vec::new(); // no type!
v.push(10u32); // apparently v is Vec<u32>?!
// v.push(10i32); // type error
What are the rules for type inference and type deduction?