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

Better error for missing tuple pattern in args #44150

Closed
Xion opened this issue Aug 29, 2017 · 1 comment
Closed

Better error for missing tuple pattern in args #44150

Xion opened this issue Aug 29, 2017 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics

Comments

@Xion
Copy link

Xion commented Aug 29, 2017

Playground link

fn main() {
    let v = vec![1, 2, 3];
    let v2: Vec<_> = v.into_iter().enumerate().map(|i, x| i).collect();
    println!("{:?}", v2);
}

Currently, this produces a somewhat confusing error:

error[E0593]: closure takes 2 arguments but 1 argument is required
 --> src/main.rs:3:48
  |
3 |     let v2: Vec<_> = v.into_iter().enumerate().map(|i, x| i).collect();
  |                                                ^^^ -------- takes 2 arguments
  |                                                |
  |                                                expected closure that takes 1 argument

which could potentially be improved for this common case (an N-tuple was expected, but the closure takes N arguments instead). This could extend to other cases where there is a tuple : multiple arguments mismatch.

@shepmaster shepmaster added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 1, 2017
@estebank estebank added the WG-diagnostics Working group: Diagnostics label Oct 13, 2017
bors added a commit that referenced this issue Oct 13, 2017
Better error for missing tuple pattern in args

#44150

Before:
```
error[E0593]: closure takes 2 arguments but 1 argument is required
 --> test.rs:5:40
  |
5 |     let it = v.into_iter().enumerate().map(|i, x| i);
  |                                        ^^^ -------- takes 2 arguments
  |                                        |
  |                                        expected closure that takes 1 argument
```

After:
```
error[E0593]: closure takes 2 arguments but a 2-tuple is required
 --> test.rs:5:40
  |
5 |     let it = v.into_iter().enumerate().map(|i, x| i);
  |                                        ^^^ ------ takes 2 arguments
  |                                        |
  |                                        expected closure that takes a 2-tuple
```
@estebank
Copy link
Contributor

estebank commented Nov 4, 2017

The original error is now handled, but leaving open to keep track of the following case that still needs to be handled:

 18 |     f(|(x, y)| x + y);
    |     ^ -------- takes a single tuple as an argument
    |     | |
    |     | help: consider changing to: `|x, y|`
    |     |
    |     expected closure that takes 2 arguments

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jan 20, 2018
Closure argument mismatch tweaks

 - use consistent phrasing for expected and found arguments
 - suggest changing arguments to tuple if possible
 - suggest changing single tuple argument to arguments if possible

Fix rust-lang#44150.
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests

3 participants