Closed
Description
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