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

E0593 could suggest using tuple as closure arg #123870

Open
matthiaskrgr opened this issue Apr 12, 2024 · 1 comment
Open

E0593 could suggest using tuple as closure arg #123870

matthiaskrgr opened this issue Apr 12, 2024 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

` stderr.lines().enumerate().find(|i, line| line == ice_msg)`

Current output

Checking icemaker v0.1.0 (/home/matthias/vcs/github/icemaker_tree_update/icemaker)
error[E0593]: closure is expected to take 1 argument, but it takes 2 arguments
    --> src/main.rs:1082:44
     |
1082 |                 stderr.lines().enumerate().find(|i, line| line == ice_msg)
     |                                            ^^^^ --------- takes 2 arguments
     |                                            |
     |                                            expected closure that takes 1 argument

For more information about this error, try `rustc --explain E0593`.

Desired output

something like help/hint:
wrap the closure args in a tuple

1082 |                 stderr.lines().enumerate().find(|(i, line)| line == ice_msg)
     | +                                               -+-------+- warp closure args in a tuple

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.79.0-nightly (a07f3eb43 2024-04-11)
binary: rustc
commit-hash: a07f3eb43acc5df851e15176c7081a900a30a4d7
commit-date: 2024-04-11
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly

Anything else?

No response

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. labels Apr 12, 2024
@eggyal
Copy link
Contributor

eggyal commented Apr 13, 2024

I wonder what the conditions for this should be?

  • only suggest if the closure is expected to take one argument but actually takes more than one? (E0593)
  • only suggest if the closure is expected to take one tuple argument but actually takes more than one?
  • only suggest if the closure is expected to take one n-tuple argument but actually takes n?
  • only suggest if the closure is expected to take (A, B, ..) argument but actually takes A, B, ..? (might not play well with inference)

Obviously none of these would help with closures that are expected to take multiple arguments, eg a tuple and something else, but it could get exponentially more difficult to identify a sensible suggestion in such cases.

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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants