Rust-GCC / Rust-GCC/gccrs

E0428 when enum variant and generic parameter share the same name

Open
#4,687 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

name resolution subset-error
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
20h 2m
Merged PRs (30d)
66

Description

Summary

the compiler incorrectly throws an E0428 ("defined multiple times") error when an enum variant has the exact same name as a generic type parameter.

Reproducer

I tried this code:

pub enum ForceResult<Leaf, Internal> {
    Leaf(Leaf),
    Internal(Internal),
}
Does the code make use of any (1.49) nightly feature ?
  • Nightly
Godbolt link

https://godbolt.org/z/5TM7v5ce9

Actual behavior
test.rs:5:5: error: ‘Leaf’ defined multiple times [E0428]
    4 | pub enum ForceResult<Leaf, Internal> {
      |                      ~~~~
    5 |     Leaf(Leaf),
      |     ^~~~
test.rs:6:5: error: ‘Internal’ defined multiple times [E0428]
    4 | pub enum ForceResult<Leaf, Internal> {
      |                            ~~~~~~~~
    5 |     Leaf(Leaf),
    6 |     Internal(Internal),
      |     ^~~~~~~~
Expected behavior

Compiler returned: 0

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

No source file or test is named. Start by compiling the provided ForceResult reproducer, then trace the compiler's name-resolution path for enum variants and generic parameters; done means the reproducer compiles without E0428 while preserving the expected variant and parameter types.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.