Skip to content

unreachable_pattern could get more specific if the preempting pattern resembles a const #129631

Open
@vDorst

Description

@vDorst

matchallways picks the first arm if matching value is not defined/unknown.
I was using constto define the values for the arms.
But the const were places inside the main() and the match expression was in a separate function.

I tried this code:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4b8fce2e782604f738c4fb9229b2a29b

Uncommenting the first 2 const gives the wanted results.

I expected to see this happen:

That the compiler finds the const values or stop compiling because the matching values are unknown.

Instead, this happened:

It just compiles.
But it gives some warnings like warning: unreachable pattern.
It just runs but with the wrong values.

See play link. See the behavior on all the versions "Stable", "Beta" and "Nightly".

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-patternsRelating to patterns and pattern matchingC-bugCategory: This is a bug.L-unreachable_patternsLint: unreachable_patternsT-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