Skip to content

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

@Aloso

Description

@Aloso

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions