Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #12099 - bitgaoshu:master, r=flodiebold
fix #11986 Aliases break resolution of qualified variants in patterns
bors 2022-05-01
parent 3eb8b28 · parent 7900d99 · commit e025b37
-rw-r--r--crates/hir_ty/src/infer.rs3
-rw-r--r--crates/hir_ty/src/tests/simple.rs19
2 files changed, 21 insertions, 1 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs
index 1892e30a42..7f5ad41509 100644
--- a/crates/hir_ty/src/infer.rs
+++ b/crates/hir_ty/src/infer.rs
@@ -735,7 +735,8 @@ impl<'a> InferenceContext<'a> {
unresolved: Option<usize>,
path: &Path,
) -> (Ty, Option<VariantId>) {
- match unresolved {
+ let remaining = unresolved.map(|x| path.segments().skip(x).len()).filter(|x| x > &0);
+ match remaining {
None => {
let variant = ty.as_adt().and_then(|(adt_id, _)| match adt_id {
AdtId::StructId(s) => Some(VariantId::StructId(s)),
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs
index baed34ce23..d4d61c2167 100644
--- a/crates/hir_ty/src/tests/simple.rs
+++ b/crates/hir_ty/src/tests/simple.rs
@@ -1588,6 +1588,16 @@ fn infer_type_alias() {
z.x;
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#"
115..116 'x': A<u32, i128>
@@ -1606,6 +1616,15 @@ fn infer_type_alias() {
195..198 'z.x': u8
204..205 'z': A<u8, 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
"#]],
)
}