Auto merge of #12099 - bitgaoshu:master, r=flodiebold

fix #11986 Aliases break resolution of qualified variants in patterns
This commit is contained in:
bors 2022-05-01 08:49:58 +00:00
commit e025b37df6
2 changed files with 21 additions and 1 deletions

View file

@ -735,7 +735,8 @@ impl<'a> InferenceContext<'a> {
unresolved: Option<usize>, unresolved: Option<usize>,
path: &Path, path: &Path,
) -> (Ty, Option<VariantId>) { ) -> (Ty, Option<VariantId>) {
match unresolved { let remaining = unresolved.map(|x| path.segments().skip(x).len()).filter(|x| x > &0);
match remaining {
None => { None => {
let variant = ty.as_adt().and_then(|(adt_id, _)| match adt_id { let variant = ty.as_adt().and_then(|(adt_id, _)| match adt_id {
AdtId::StructId(s) => Some(VariantId::StructId(s)), AdtId::StructId(s) => Some(VariantId::StructId(s)),

View file

@ -1588,6 +1588,16 @@ fn infer_type_alias() {
z.x; z.x;
z.y; z.y;
} }
mod m {
pub enum Enum {
Foo(u8),
}
pub type Alias = Enum;
}
fn f() {
let e = m::Alias::Foo(0);
let m::Alias::Foo(x) = &e;
}
"#, "#,
expect![[r#" expect![[r#"
115..116 'x': A<u32, i128> 115..116 'x': A<u32, i128>
@ -1606,6 +1616,15 @@ fn infer_type_alias() {
195..198 'z.x': u8 195..198 'z.x': u8
204..205 'z': A<u8, i8> 204..205 'z': A<u8, i8>
204..207 'z.y': i8 204..207 'z.y': i8
298..362 '{ ... &e; }': ()
308..309 'e': Enum
312..325 'm::Alias::Foo': Foo(u8) -> Enum
312..328 'm::Ali...Foo(0)': Enum
326..327 '0': u8
338..354 'm::Ali...Foo(x)': Enum
352..353 'x': &u8
357..359 '&e': &Enum
358..359 'e': Enum
"#]], "#]],
) )
} }