Skip to content

Generics: Make enum variant syntax consistent with other types #2218

Closed
rust-lang/rust
#61682
rust-lang/rust#61682

Description

Accessing generics in Rust roughly revolves around the below syntax today:

Item Syntax
Type T::<VARIANT>::Item
Method Calls Function::<VARIANT>()
Enum T::Item::<VARIANT>

While the first are second are fairly consistent, the enum one is weird and almost has an opposite syntax. The reasons mostly seem to be just historical for the inconsistency.

To illustrate it with an example:

let x = None::<i32>;             // OK
let x = Option::<i32>::None;     // Compiler error. (But this is the type syntax)

I think it would be nicer to allow a more consistent syntax, that allow enum to be work with the Type syntax as above.

Potential side-effects:

While bringing this up in the IRC, one of the nice folks pointed this very useful feature out - with the existing syntax, you can do use self::Enum::Variant; and then have Variant(foo) in the code. But this can easily be achieved with type aliasing, with the above syntax - making it even more consistent with other types.

While the existing syntax may or may not be deprecated at a later stage - I think adding a consistent syntax would be very useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions