Skip to content

Tuple struct/variant patterns don't work with type aliases #31659

@petrochenkov

Description

@petrochenkov
struct S(u8);
type Z = S;

fn main() {
    match S(80) {
        S(x) => {} // ok
    }
    match S(90) {
        Z(x) => {} // error: unresolved enum variant, struct or const `Z` [E0419]
    }
}

For some reason names of tuple struct/variant patterns are searched for in the value namespace and not in the type namespace.
This is strange, because S here is a name of the type, not constructor function, and S(x) is not a function call.
S and Z should probably be searched in the type namespace, like names of struct patterns S{..}.
Theoretically such change can break code, but only in highly contrived cases.

@jseyfried @nrc what do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    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