Skip to content

Show types of all args when missing args #34000

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

Merged
merged 1 commit into from
Jun 16, 2016
Merged

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Jun 1, 2016

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

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

fn t(a: &str, x: String) {}
% 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

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jroesch (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@estebank estebank force-pushed the missingargs branch 3 times, most recently from 49aa08c to aa489af Compare June 1, 2016 06:55
&format!("the following parameter type{} expected: {}",
if expected_arg_count == 1 {" was"} else {"s were"},
input_types.join(", ")));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be in its own function to reduce code repetition (this would allow E0057, E0060 and E0061 to be merged into a single error number).

Also it should be using the error builders, so you can attach the note to the main error.

Copy link
Contributor Author

@estebank estebank Jun 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I left the error codes separate because I feel changing that behaviour would be incorrect.

@estebank estebank force-pushed the missingargs branch 2 times, most recently from 83fc815 to 8ab4aaa Compare June 3, 2016 00:57
@estebank
Copy link
Contributor Author

estebank commented Jun 3, 2016

r? @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Jun 4, 2016

Sorry ^^ I'm not a reviewer

@estebank
Copy link
Contributor Author

estebank commented Jun 4, 2016

@oli-obk not a problem :)

err.emit();
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just one newline here would be more idiomatic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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
@jseyfried
Copy link
Contributor

Thanks! @bors r+

@bors
Copy link
Collaborator

bors commented Jun 16, 2016

📌 Commit 1020e30 has been approved by jseyfried

@bors
Copy link
Collaborator

bors commented Jun 16, 2016

⌛ Testing commit 1020e30 with merge 7339eca...

bors added a commit that referenced this pull request 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
@bors bors merged commit 1020e30 into rust-lang:master Jun 16, 2016
@estebank estebank deleted the missingargs branch November 9, 2023 05:28
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

Successfully merging this pull request may close these issues.

6 participants