Skip to content

Bad recovery for <expression> ? <statement> ; #117208

Closed
@bend-n

Description

@bend-n

Code

pub fn foo() {
  let v = v?
  while let Ok(_) = v {};
}

Current output

error: expected one of `.`, `;`, `?`, `else`, or an operator, found `;`
 --> src/main.rs:4:25
  |
4 |   while let Ok(_) = v {};
  |                         ^ expected one of `.`, `;`, `?`, `else`, or an operator

Desired output

error: expected `;`, found `while`
 --> src/main.rs:4:25
  |
3 |  let v = v?
  |            ^ help: add ';' here

Rationale and extra context

Confusing error

Other cases

Removing the semicolon as suggested causes

error: expected `;`, found `}`
 --> src/main.rs:4:25
  |
4 |   while let Ok(_) = v {}
  |                         ^ help: add `;` here
5 | }
  | - unexpected token

error[E0425]: cannot find value `v` in this scope
 --> src/main.rs:3:11
  |
3 |   let v = v?
  |           ^ not found in this scope

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

Anything else?

Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTT-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