Skip to content

Insufficient arguments error E0061 & E0050 would be more helpful if it printed what arguments are needed #33649

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

Closed
kornelski opened this issue May 15, 2016 · 6 comments

Comments

@kornelski
Copy link
Contributor

kornelski commented May 15, 2016

When I call a function with insufficient arguments, rustc just says the number of arguments is wrong.

:4:5: 4:26 error: this function takes 1 parameter but 0 parameters were supplied [E0061]
:4 std::fs::File::open();
^~~~~~~~~~~~~~~~~~~~~

This would be much more helpful if it said which arguments, and what they are, e.g.:

error: The path argument was not supplied to the open function

or at least show the funcition definition in a note:

:4:5: 4:26 error: this function takes 1 parameter but 0 parameters were supplied [E0061]
:4 std::fs::File::open();
note: fn open<P: AsRef<Path>>(path: P) -> Result<File>

Similar problem applies to E0050 ("error: method foo has 1 parameter but the declaration in trait bar has 2").


rustc 1.10.0-nightly (2b79e05 2016-05-13)

@GuillaumeGomez
Copy link
Member

Showing which parameter isn't supplied is quite difficult. It could be any and rustc should guess what argument you forgot between all arguments. Quite difficult.

However, showing the function definition in a note seems a nice idea.

@jonas-schievink
Copy link
Contributor

@GuillaumeGomez the function definition might be in another crate, so you'd have to reconstruct it from metadata.

@kornelski
Copy link
Contributor Author

@GuillaumeGomez I think it'd be sufficient to list remaining arguments only (if I supplied 3, but 5 are required, show last 2). That's because if I got order of arguments wrong, it'll hopefully be picked by type checker, and that's a different error. Listing names (and types) of all arguments would be OK too.

@GuillaumeGomez
Copy link
Member

@GuillaumeGomez I think it'd be sufficient to list remaining arguments only (if I supplied 3, but 5 are required, show last 2). That's because if I got order of arguments wrong, it'll hopefully be picked by type checker, and that's a different error. Listing names (and types) of all arguments would be OK too.

Like I said, how do rustc can guess if you entered the 3 first or the 3 last? Or that they're even in the good order?

@GuillaumeGomez the function definition might be in another crate, so you'd have to reconstruct it from metadata.

That was just a guess. 😉

@sanmai-NL
Copy link

Could you also add the Rust version info here to your post? You'll help to make this issue tracker a more useful archive/reference in the future.

estebank added a commit to estebank/rust that referenced this issue Jun 16, 2016
When there're missing arguments in a function call, present a list of
all the expected types:

```rust
fn main() {
    t("");
}

fn t(a: &str, x: String) {}
```

```bash
% rustc file.rs
file.rs:3:5: 2:8 error: this function takes 2 parameters but 0
parameters were supplied [E0061]
file.rs:3     t();
              ^~~
file.rs:3:5: 2:8 help: run `rustc --explain E0061` to see a detailed explanation
file.rs:3:5: 2:8 note: the following parameter types were expected: &str, std::string::String
error: aborting due to previous error
```

Fixes rust-lang#33649
bors added a commit that referenced this issue Jun 16, 2016
Show types of all args when missing args

When there're missing arguments in a function call, present a list of
all the expected types:

```rust
fn main() {
    t("");
}

fn t(a: &str, x: String) {}
```

```bash
% rustc file.rs
file.rs:3:5: 2:8 error: this function takes 2 parameters but 0
parameters were supplied [E0061]
file.rs:3     t();
              ^~~
file.rs:3:5: 2:8 help: run `rustc --explain E0061` to see a detailed explanation
file.rs:3:5: 2:8 note: the following parameter types were expected: &str, std::string::String
error: aborting due to previous error
```

Fixes #33649
@kornelski
Copy link
Contributor Author

Thank you @estebank for fixing this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants