about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2025-05-02 20:46:54 +0000
committerGitHub <noreply@github.com>2025-05-02 20:46:54 +0000
commit4e3bdb96d93443bf4c9ba0c0a8b0515217e75a0d (patch)
treef2139fe1938d96d37a1eb3a149dc29576973ca2f
parent372f3f30387b7cb2fca1c9c82119d170eb3884c8 (diff)
parent9eb1e83a12121302dd5ae09c7ba419de08e2da34 (diff)
downloadrust-4e3bdb96d93443bf4c9ba0c0a8b0515217e75a0d.tar.gz
rust-4e3bdb96d93443bf4c9ba0c0a8b0515217e75a0d.zip
Merge pull request #19732 from ShoyuVanilla/issue-19730
fix: Correct assoc ty bound var starting index
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs5
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs23
2 files changed, 27 insertions, 1 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs b/src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs
index 376daccbdae..cd799c03ddf 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs
@@ -637,7 +637,10 @@ pub(crate) fn associated_ty_data_query(
         .fill_with_bound_vars(crate::DebruijnIndex::INNERMOST, 0)
         .build();
     let pro_ty = TyBuilder::assoc_type_projection(db, type_alias, Some(trait_subst))
-        .fill_with_bound_vars(crate::DebruijnIndex::INNERMOST, generic_params.len_self())
+        .fill_with_bound_vars(
+            crate::DebruijnIndex::INNERMOST,
+            generic_params.parent_generics().map_or(0, |it| it.len()),
+        )
         .build();
     let self_ty = TyKind::Alias(AliasTy::Projection(pro_ty)).intern(Interner);
 
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
index 644b0d392bc..47c695c6974 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
@@ -2278,3 +2278,26 @@ fn test(x: bool) {
         "#]],
     );
 }
+
+#[test]
+fn issue_19730() {
+    check_infer(
+        r#"
+trait Trait<T = Self> {}
+
+trait Foo {
+    type Bar<A, B>: Trait;
+
+    fn foo<A, B>(bar: Self::Bar<A, B>) {
+        let _ = bar;
+    }
+}
+"#,
+        expect![[r#"
+            83..86 'bar': Foo::Bar<Self, A, B>
+            105..133 '{     ...     }': ()
+            119..120 '_': Foo::Bar<Self, A, B>
+            123..126 'bar': Foo::Bar<Self, A, B>
+        "#]],
+    );
+}