Skip to content

Commit e025b37

Browse files
committed
Auto merge of rust-lang#12099 - bitgaoshu:master, r=flodiebold
fix rust-lang#11986 Aliases break resolution of qualified variants in patterns
2 parents 3eb8b28 + 7900d99 commit e025b37

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

crates/hir_ty/src/infer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,8 @@ impl<'a> InferenceContext<'a> {
735735
unresolved: Option<usize>,
736736
path: &Path,
737737
) -> (Ty, Option<VariantId>) {
738-
match unresolved {
738+
let remaining = unresolved.map(|x| path.segments().skip(x).len()).filter(|x| x > &0);
739+
match remaining {
739740
None => {
740741
let variant = ty.as_adt().and_then(|(adt_id, _)| match adt_id {
741742
AdtId::StructId(s) => Some(VariantId::StructId(s)),

crates/hir_ty/src/tests/simple.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,16 @@ fn infer_type_alias() {
15881588
z.x;
15891589
z.y;
15901590
}
1591+
mod m {
1592+
pub enum Enum {
1593+
Foo(u8),
1594+
}
1595+
pub type Alias = Enum;
1596+
}
1597+
fn f() {
1598+
let e = m::Alias::Foo(0);
1599+
let m::Alias::Foo(x) = &e;
1600+
}
15911601
"#,
15921602
expect![[r#"
15931603
115..116 'x': A<u32, i128>
@@ -1606,6 +1616,15 @@ fn infer_type_alias() {
16061616
195..198 'z.x': u8
16071617
204..205 'z': A<u8, i8>
16081618
204..207 'z.y': i8
1619+
298..362 '{ ... &e; }': ()
1620+
308..309 'e': Enum
1621+
312..325 'm::Alias::Foo': Foo(u8) -> Enum
1622+
312..328 'm::Ali...Foo(0)': Enum
1623+
326..327 '0': u8
1624+
338..354 'm::Ali...Foo(x)': Enum
1625+
352..353 'x': &u8
1626+
357..359 '&e': &Enum
1627+
358..359 'e': Enum
16091628
"#]],
16101629
)
16111630
}

0 commit comments

Comments
 (0)