Skip to content

diagnostic could be better whe using "..." instead of ".." when destructuring enum #70388

Closed
@matthiaskrgr

Description

@matthiaskrgr
enum MyEnum {
    A(i32),
    B(u32),
}

fn use_enum(e: MyEnum) {
    if let MyEnum::A(...) = e {
        println!("got enum")
    };
}

The problem here is that we have if let MyEnum::A(...) = e instead of if let MyEnum::A(..) = e

The compiler however points towards ) in the error message instead of the superfluous .:

 error: unexpected token: `)`
 --> src/main.rs:7:25
  |
7 |     if let MyEnum::A(...) = e {
  |                         ^

error: aborting due to previous error

Fun fact: when using four dots MyEnum::A(....), it correctly points at the last dot :)

error: unexpected token: `.`
 --> src/main.rs:7:25
  |
7 |     if let MyEnum::A(....) = e {
  |                         ^

error: aborting due to previous error

This issue has been assigned to @rakshith-ravi via this comment.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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