E0428 when enum variant and generic parameter share the same name
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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