Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propose a FIXIT when the return type is missing from the function definition #35478

Closed
dcci opened this issue Aug 7, 2016 · 1 comment
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@dcci
Copy link

dcci commented Aug 7, 2016

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.

@dcci dcci changed the title Propose a FIXIT when the return type is missed from the function definition Propose a FIXIT when the return type is missing from the function definition Aug 7, 2016
@Mark-Simulacrum Mark-Simulacrum added the A-diagnostics Area: Messages for errors, warnings, and lints label May 10, 2017
@Mark-Simulacrum
Copy link
Member

Closing in favor of collective issue for this general problem: #41897.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

2 participants