Closed
Description
fn get_numbers(arr1 : String) {
let num1 : Vec<i32> =
arr1.split_whitespace().map(|s| s.parse().unwrap()).collect();
return num1;
}
fn main() {
let str = String::from("1 2 3 4");
let num1 : Vec<i32> = get_numbers(str);
println!("{}", num1[0]);
}
This obviously fails with:
triplets.rs:4:10: 4:14 error: mismatched types:
expected `()`,
found `collections::vec::Vec<i32>`
(expected (),
found struct `collections::vec::Vec`) [E0308]
triplets.rs:4 return num1;
^~~~
triplets.rs:4:10: 4:14 help: run `rustc --explain E0308` to see a detailed explanation
I think the compiler should try to propose a FIXIT
, e.g.
maybe did you mean fn get_numbers(arr1 : String) -> Vec<i32>
Also, rustc --explain E0308
doesn't list the missing -> return_type
case as "common mistake". Not sure if it's really worth listing it, but still, worth mentioning.