Skip to content

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

Closed
@estebank

Description

@estebank

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions