diff --git a/crates/hir-ty/src/chalk_db.rs b/crates/hir-ty/src/chalk_db.rs index 6972db8495..af2aa96574 100644 --- a/crates/hir-ty/src/chalk_db.rs +++ b/crates/hir-ty/src/chalk_db.rs @@ -410,8 +410,10 @@ pub(crate) fn associated_ty_data_query( let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); let ctx = crate::TyLoweringContext::new(db, &resolver) .with_type_param_mode(crate::lower::ParamLoweringMode::Variable); - let self_ty = - TyKind::BoundVar(BoundVar::new(crate::DebruijnIndex::INNERMOST, 0)).intern(Interner); + let pro_ty = TyBuilder::assoc_type_projection(db, type_alias) + .fill_with_bound_vars(crate::DebruijnIndex::INNERMOST, 0) + .build(); + let self_ty = TyKind::Alias(AliasTy::Projection(pro_ty)).intern(Interner); let mut bounds: Vec<_> = type_alias_data .bounds .iter() diff --git a/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs index b1d295ca34..a11b026df5 100644 --- a/crates/hir-ty/src/tests/traits.rs +++ b/crates/hir-ty/src/tests/traits.rs @@ -1,7 +1,7 @@ use cov_mark::check; use expect_test::expect; -use super::{check, check_infer, check_infer_with_mismatches, check_types}; +use super::{check, check_infer, check_infer_with_mismatches, check_no_mismatches, check_types}; #[test] fn infer_await() { @@ -3316,6 +3316,42 @@ pub trait Deserialize { ); } +#[test] +fn bin_op_with_rhs_is_self_for_assoc_bound() { + check_no_mismatches( + r#"//- minicore: eq + fn repro(t: T) -> bool +where + T: Request, + T::Output: Convertable, +{ + let a = execute(&t).convert(); + let b = execute(&t).convert(); + a.eq(&b); + let a = execute(&t).convert2(); + let b = execute(&t).convert2(); + a.eq(&b) +} +fn execute(t: &T) -> T::Output +where + T: Request, +{ + ::output() +} +trait Convertable { + type TraitSelf: PartialEq; + type AssocAsDefaultSelf: PartialEq; + fn convert(self) -> Self::AssocAsDefaultSelf; + fn convert2(self) -> Self::TraitSelf; +} +trait Request { + type Output; + fn output() -> Self::Output; +} + "#, + ); +} + #[test] fn bin_op_adt_with_rhs_primitive() { check_infer_with_mismatches(