Skip to content

Commit 9eb1e83

Browse files
committed
fix: Correct assoc ty bound var starting index
1 parent 3686ed9 commit 9eb1e83

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,10 @@ pub(crate) fn associated_ty_data_query(
637637
.fill_with_bound_vars(crate::DebruijnIndex::INNERMOST, 0)
638638
.build();
639639
let pro_ty = TyBuilder::assoc_type_projection(db, type_alias, Some(trait_subst))
640-
.fill_with_bound_vars(crate::DebruijnIndex::INNERMOST, generic_params.len_self())
640+
.fill_with_bound_vars(
641+
crate::DebruijnIndex::INNERMOST,
642+
generic_params.parent_generics().map_or(0, |it| it.len()),
643+
)
641644
.build();
642645
let self_ty = TyKind::Alias(AliasTy::Projection(pro_ty)).intern(Interner);
643646

src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,3 +2278,26 @@ fn test(x: bool) {
22782278
"#]],
22792279
);
22802280
}
2281+
2282+
#[test]
2283+
fn issue_19730() {
2284+
check_infer(
2285+
r#"
2286+
trait Trait<T = Self> {}
2287+
2288+
trait Foo {
2289+
type Bar<A, B>: Trait;
2290+
2291+
fn foo<A, B>(bar: Self::Bar<A, B>) {
2292+
let _ = bar;
2293+
}
2294+
}
2295+
"#,
2296+
expect![[r#"
2297+
83..86 'bar': Foo::Bar<Self, A, B>
2298+
105..133 '{ ... }': ()
2299+
119..120 '_': Foo::Bar<Self, A, B>
2300+
123..126 'bar': Foo::Bar<Self, A, B>
2301+
"#]],
2302+
);
2303+
}

0 commit comments

Comments
 (0)