about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-18 15:08:36 +0000
committerbors <bors@rust-lang.org>2023-12-18 15:08:36 +0000
commitf6635211ce8a208e11c9c809a80b66aaf2240eb7 (patch)
tree6e691ce2ac3712e5d554a73aaf3fdd316107e96a
parentae2c3223b0dfdfa9c0815760901ace12c08d7747 (diff)
parentbd61888b8db35965cca9ff46119615cbc73448a0 (diff)
downloadrust-f6635211ce8a208e11c9c809a80b66aaf2240eb7.tar.gz
rust-f6635211ce8a208e11c9c809a80b66aaf2240eb7.zip
Auto merge of #16152 - Austaras:alias, r=Veykril
fix: resolve alias before resolve variant

Closes #15943 (again)
-rw-r--r--crates/hir-ty/src/infer.rs6
-rw-r--r--crates/hir-ty/src/tests/patterns.rs34
2 files changed, 40 insertions, 0 deletions
diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs
index 6f724e45874..e295dd8d4e1 100644
--- a/crates/hir-ty/src/infer.rs
+++ b/crates/hir-ty/src/infer.rs
@@ -1200,6 +1200,12 @@ impl<'a> InferenceContext<'a> {
         path: &ModPath,
     ) -> (Ty, Option<VariantId>) {
         let remaining = unresolved.map(|it| path.segments()[it..].len()).filter(|it| it > &0);
+        let ty = match ty.kind(Interner) {
+            TyKind::Alias(AliasTy::Projection(proj_ty)) => {
+                self.db.normalize_projection(proj_ty.clone(), self.table.trait_env.clone())
+            }
+            _ => ty,
+        };
         match remaining {
             None => {
                 let variant = ty.as_adt().and_then(|(adt_id, _)| match adt_id {
diff --git a/crates/hir-ty/src/tests/patterns.rs b/crates/hir-ty/src/tests/patterns.rs
index 7234af2d683..548f782f4f2 100644
--- a/crates/hir-ty/src/tests/patterns.rs
+++ b/crates/hir-ty/src/tests/patterns.rs
@@ -1155,6 +1155,40 @@ fn main() {
 }
 
 #[test]
+fn generic_alias_with_qualified_path() {
+    check_types(
+        r#"
+type Wrap<T> = T;
+
+struct S;
+
+trait Schematic {
+    type Props;
+}
+
+impl Schematic for S {
+    type Props = X;
+}
+
+enum X {
+    A { cool: u32, stuff: u32 },
+    B,
+}
+
+fn main() {
+    let wrapped = Wrap::<<S as Schematic>::Props>::A {
+        cool: 100,
+        stuff: 100,
+    };
+
+    if let Wrap::<<S as Schematic>::Props>::A { cool, ..} = &wrapped {}
+                                              //^^^^ &u32
+}
+"#,
+    );
+}
+
+#[test]
 fn type_mismatch_pat_const_reference() {
     check_no_mismatches(
         r#"