1
Fork 0

Auto merge of #95380 - compiler-errors:unit-destructure-assign, r=nikomatsakis

Fix unit struct/enum variant in destructuring assignment

See https://github.com/rust-lang/rfcs/blob/master/text/2909-destructuring-assignment.md#guide-level-explanation, "including **unit** and tuple structs"

Fixes #94319
This commit is contained in:
bors 2022-05-03 22:29:58 +00:00
commit 1b2e0b60cc
4 changed files with 80 additions and 7 deletions

View file

@ -396,13 +396,10 @@ impl<'a> PathSource<'a> {
) | Res::Local(..)
| Res::SelfCtor(..)
),
PathSource::Pat => matches!(
res,
Res::Def(
DefKind::Ctor(_, CtorKind::Const) | DefKind::Const | DefKind::AssocConst,
_,
) | Res::SelfCtor(..)
),
PathSource::Pat => {
res.expected_in_unit_struct_pat()
|| matches!(res, Res::Def(DefKind::Const | DefKind::AssocConst, _))
}
PathSource::TupleStruct(..) => res.expected_in_tuple_struct_pat(),
PathSource::Struct => matches!(
res,