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

Misparse in for expressions always suggest wrapping with a body, when it might be something else #132656

Open
estebank opened this issue Nov 5, 2024 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST 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

@estebank
Copy link
Contributor

estebank commented Nov 5, 2024

Code

fn main() {
    for _ in [1, 2, 3].iter()map(|x| x) {}
}

Current output

error: expected `{`, found `map`
 --> src/main.rs:2:30
  |
2 |     for _ in [1, 2, 3].iter()map(|x| x) {}
  |                              ^^^ expected `{`
  |
help: try placing this code inside a block
  |
2 |     for _ in [1, 2, 3].iter(){ map(|x| x) } {}
  |                              +            +

Desired output

error: expected `{`, found `map`
 --> src/main.rs:2:30
  |
2 |     for _ in [1, 2, 3].iter()map(|x| x) {}
  |                              ^^^ expected `{`
  |
help: you might have meant to call a method
  |
2 |     for _ in [1, 2, 3].iter().map(|x| x) {}
  |                              +

Rationale and extra context

No response

Other cases

No response

Rust Version

1.82

Anything else?

No response

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST 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. labels Nov 5, 2024
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-parser Area: The parsing of Rust source code to an AST 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

No branches or pull requests

1 participant