How do I annotate the type of an empty slice in Rust?
问题 Suppose I want to compare a Vec<String> to a literal empty list in a test. (I'm aware that in practice I could check is_empty() , but I'd like to understand how Rust typing works here, and I think asserting equality will give a clearer message if it fails.) If I just say let a: Vec<String> = Vec::new(); assert_eq!(a, []); I get an error that error[E0282]: type annotations needed --> src/main.rs:3:5 | 3 | assert_eq!(a, []); | ^^^^^^^^^^^^^^^^^^ cannot infer type | = note: this error originates