Skip to content

#![feature(type_alias_enum_variants)]: Unit variant pattern through a type alias to generic enum requires type annotations #61801

Closed
@Centril

Description

@Centril

The following, which I expect to work, fails to infer the type of OptAlias::None:

#![feature(type_alias_enum_variants)]

enum Option<T> {
    None,
    Some(T),
}

type OptAlias<T> = Option<T>;

fn work_on_alias(x: OptAlias<u8>) {
    match x {
        OptAlias::None => (), //~ ERROR type annotations needed
        _ => (),
    }
}

In HIR, OptAlias::None should correspond to:

PatKind::Path(
    QPath::TypeRelative(_, P(
        PathSegment { res: Some(
            Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const))
        ), .. }
    ))
)

However, if we change the snippet to:

#![feature(type_alias_enum_variants)]

enum Option<T> {
    None,
    Some(T),
}

type OptAlias<T> = Option<T>;

fn work_on_alias(x: OptAlias<u8>) {
    match x {
        OptAlias::None {} => (), // Note the changed pattern.
        _ => (),
    }
}

it all works out fine.

I also tested changing None to a tuple variant and that works also.

cc @petrochenkov @eddyb @alexreg

cc #61682

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions