Skip to content

error help suggests writing down a closure type, which would be a syntax error #91832

New issue

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

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

Already on GitHub? # to your account

Closed
jendrikw opened this issue Dec 12, 2021 · 1 comment · Fixed by #91898
Closed

error help suggests writing down a closure type, which would be a syntax error #91832

jendrikw opened this issue Dec 12, 2021 · 1 comment · Fixed by #91898
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jendrikw
Copy link
Contributor

jendrikw commented Dec 12, 2021

Given the following code: play

fn f() {
    vec!['a'].iter().map(|c| c)
}

The current output is:

error[E0308]: mismatched types
 --> src/lib.rs:2:5
  |
2 |     vec!['a'].iter().map(|c| c)
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `Map`
  |
  = note: expected unit type `()`
                found struct `Map<std::slice::Iter<'_, char>, [closure@src/lib.rs:2:26: 2:31]>`
help: consider using a semicolon here
  |
2 |     vec!['a'].iter().map(|c| c);
  |                                +
help: try adding a return type
  |
1 | fn f() -> Map<std::slice::Iter<'_, char>, [closure@src/lib.rs:2:26: 2:31]> {
  |        +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Ideally the output should look like:

Don't suggest adding -> Map<std::slice::Iter<'_, char>, [closure@src/lib.rs:2:26: 2:31]> if that's not going to compile.

@jendrikw jendrikw 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. labels Dec 12, 2021
@hkmatsumoto hkmatsumoto added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Dec 13, 2021
@compiler-errors
Copy link
Member

@rustbot claim

# for free to join this conversation on GitHub. Already have an account? # 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` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants