Skip to content

Error for incorrect identifier patterns could be improved #65400

Closed
@tesuji

Description

@tesuji

The compiler could suggest that e identifier must precede the pattern in the following code:

playpen link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ca2dc7094a56b0478edefe0faefefe0e

fn main() {
    let x = 2;

    match x {
        1 ..= 5 @ e => {}
        _ => {}
    }
}

Current error message:

error: expected one of `=>`, `if`, or `|`, found `@`
 --> src/main.rs:5:17
  |
5 |         1 ..= 5 @ e => {}
  |                 ^ expected one of `=>`, `if`, or `|` here

error: aborting due to previous error

It could be improved as:

error: expected one of `=>`, `if`, or `|`, found `@`
 --> src/main.rs:5:17
  |
5 |         1 ..= 5 @ e => {}
  |                 ^ expected one of `=>`, `if`, or `|` here
                    | help: try `e @ 1 ..= 5`


error: aborting due to previous error

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-feature-requestCategory: A feature request, i.e: not implemented / a PR.D-papercutDiagnostics: An error or lint that needs small tweaks.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