Skip to content

Improve pattern-checking error message with variable that resembles an enum variant #4612

Closed
@Kimundi

Description

@Kimundi

This code:

mod foo {
  pub enum Bars {
    BarFoo,
    BarBar,
    BarBaz
  }
}

fn main() {
    decide(foo::BarBar);
}

fn decide(bar: foo::Bars) -> int {
    match bar {
        BarFoo => 0,
        BarBar => 42,
        BarBaz => 128
    }
}

should fail to compile because it can't resolve the enum variants in the match statement.
But currently it outputs this error message instead:

match_namespace.rs:16:8: 16:17 error: unreachable pattern
match_namespace.rs:16         BarBar => 42,
                              ^~~~~~~~~
match_namespace.rs:17:8: 17:17 error: unreachable pattern
match_namespace.rs:17         BarBaz => 128
                              ^~~~~~~~~

Which is curious because it doesn't complaint about the first item in the match statement, and because it somehow confuses 'Don't know what it is' with 'Can't reach it'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-frontendArea: Compiler frontend (errors, parsing and HIR)C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions