Skip to content

Type Alias grammar is confusing #1389

Open
@harudagondi

Description

@harudagondi

At the top, the grammar is written as:

Syntax
TypeAlias :
type IDENTIFIER GenericParams? ( : TypeParamBounds )? WhereClause? ( = Type WhereClause?)? ;

I assumed this applies to every instance of a type alias, but it's not. For example, type aliases are not allowed to have no type specified when declared as a top level item, but it is when as an associated type in a trait.

This is mentioned in the later paragraphs, however:

A type alias, when not used as an associated type, must include a Type and may not include TypeParamBounds.

A type alias, when used as an associated type in a trait, must not include a Type specification but may include TypeParamBounds.

A type alias, when used as an associated type in a trait impl, must include a Type specification and may not include TypeParamBounds.

This is confusing for me. I think it would be better if there was a syntax box like the one mentioned above for each case where a type alias can be found. So for example, these would be the syntax boxes for each:

Syntax
TypeAlias :
type IDENTIFIER GenericParams? ( : TypeParamBounds )? WhereClause? = Type WhereClause? ;

Syntax
TypeAlias :
type IDENTIFIER GenericParams? : TypeParamBounds WhereClause? ;

Syntax
TypeAlias :
type IDENTIFIER GenericParams? ( : TypeParamBounds )? WhereClause? = Type WhereClause? ;

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-grammarArea: Syntax and parsing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions