Rust-GCC / Rust-GCC/gccrs

Wrong lowering of `AST::IdentifierPattern`

Open
#3,117 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
20h 2m
Merged PRs (30d)
66

Description

Summary

AST::IdentifierPattern should lower to HIR::PathPattern only when identifiers resolve to enum variants or structs.
However, they always lower to HIR::IdentifierPattern which introduces a new binding.

See https://doc.rust-lang.org/reference/patterns.html

Reproducer

I tried this code:

enum E {
    A,
    B,
}

use E::*;

fn main() -> i32 {
    match E::B {
        A => 1,
        B => 2,
    } 
}
Does the code make use of any (1.49) nightly feature ?
  • Nightly
Godbolt link

No response

Actual behavior

The current behavior is...

$ echo $?
1
Expected behavior

I expected to see...

$ echo $?
2
GCC Version

master

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 at the lowering of AST::IdentifierPattern into HIR patterns and trace how identifier resolution distinguishes enum variants and structs from new bindings. Use the Rust reproducer as a regression case; done means the unqualified A and B patterns match E::A and E::B and produce the expected result of 2.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.