Skip to content

Accessing an associated constant with the same name as an enum variant doesn't work #75724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Aloso opened this issue Aug 19, 2020 · 1 comment
Labels
C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Aloso
Copy link
Contributor

Aloso commented Aug 19, 2020

The following code works:

enum Enum {
    Variant {}
}

impl Enum {
    const Variant: Enum = Enum::Variant {};
}

However, accessing the associated constant does not:

let _ = Enum::Variant;
// error[E0423]: expected value, found struct variant `Enum::Variant`

Explanation why I think this should work

Most items are in one of three namespaces/universes: The type namespace, the value namespace, and the macro namespace. For example, regular structs are in the type namespace, whereas constants are in the value namespace, so a struct and a constant can share the same name (this is also how unit structs are desugared):

struct S {}
const S: S = S {};

let _: S = S;

I expected the same to work for enum variants as well.

If you don't intend to fix this, please consider changing the error message, as the phrase "struct variant" can be misleading.

Meta

It can be reproduced on stable, beta and nightly. See playground.

@Aloso Aloso added the C-bug Category: This is a bug. label Aug 19, 2020
@estebank estebank added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Aug 23, 2020
@Dylan-DPC
Copy link
Member

This code now compiles fine so closing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants