Hi,
When I compile the following snippet
fn main() {
let a: Vec<Vec<usize>> = (0..10).map(|i| vec![i; i]).collect();
let f = |j| { a[j].is_empty() };
println!("{}", f(0));
}
I get
Compiling type-annot v0.1.0 (/tmp/type-annot)
error[E0282]: type annotations needed
--> src/main.rs:3:20
|
3 | let f = |j| { &a[j].is_empty() };
| ^^^^ cannot infer type
|
= note: type must be known at this point
I do not understand why as the type if a
is explicitly stated. I can help the compiler using
fn main() {
let a: Vec<Vec<usize>> = (0..10).map(|i| vec![i; i]).collect();
let f = |j| { let aj: &Vec<_> = &a[j];
aj.is_empty() };
println!("{}", f(0));
}
but why is it needed?