rust-lang / rust-lang/rust

Inconsistency between reference and compiler w.r.t. path patterns resolving to structs

Open
#155,320 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-docs A-frontend A-patterns A-resolve C-bug needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

struct Empty {}

fn test_match(i: i32) -> i32 {
    return match i {
        Empty => 1,
    };
}

I expected to see this happen:
It should fail to compile as Empty should resolve to a struct (path pattern) rather than be interpreted as an identifier pattern.
https://doc.rust-lang.org/stable/reference/patterns.html#r-patterns.path.unqualified "Unqualified path patterns can refer to (...)structs"
https://doc.rust-lang.org/stable/reference/patterns.html#r-patterns.ident.precedent "Path patterns take precedence over identifier patterns."

Instead, this happened:
The code compiled, treating Empty as an IdentifierPattern.

Meta

rustc --version --verbose:

binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.92.0
LLVM version: 21.1.3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the match expression with rustc and compare its behavior with the Reference sections on unqualified path patterns and identifier-pattern precedence. Trace the compiler's handling of the Empty pattern and add a regression test showing that this code is rejected consistently with the documented rules.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.