Skip to content

Commit c2099fe

Browse files
committed
Auto merge of rust-lang#12336 - bitgaoshu:mismatch, r=flodiebold
fix: rust-lang#12267 type-mismatch when using equals w/ a trait bound
2 parents f65d734 + 7c5e972 commit c2099fe

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

crates/hir-ty/src/chalk_db.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,10 @@ pub(crate) fn associated_ty_data_query(
410410
let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast());
411411
let ctx = crate::TyLoweringContext::new(db, &resolver)
412412
.with_type_param_mode(crate::lower::ParamLoweringMode::Variable);
413-
let self_ty =
414-
TyKind::BoundVar(BoundVar::new(crate::DebruijnIndex::INNERMOST, 0)).intern(Interner);
413+
let pro_ty = TyBuilder::assoc_type_projection(db, type_alias)
414+
.fill_with_bound_vars(crate::DebruijnIndex::INNERMOST, 0)
415+
.build();
416+
let self_ty = TyKind::Alias(AliasTy::Projection(pro_ty)).intern(Interner);
415417
let mut bounds: Vec<_> = type_alias_data
416418
.bounds
417419
.iter()

crates/hir-ty/src/tests/traits.rs

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use cov_mark::check;
22
use expect_test::expect;
33

4-
use super::{check, check_infer, check_infer_with_mismatches, check_types};
4+
use super::{check, check_infer, check_infer_with_mismatches, check_no_mismatches, check_types};
55

66
#[test]
77
fn infer_await() {
@@ -3316,6 +3316,42 @@ pub trait Deserialize {
33163316
);
33173317
}
33183318

3319+
#[test]
3320+
fn bin_op_with_rhs_is_self_for_assoc_bound() {
3321+
check_no_mismatches(
3322+
r#"//- minicore: eq
3323+
fn repro<T>(t: T) -> bool
3324+
where
3325+
T: Request,
3326+
T::Output: Convertable,
3327+
{
3328+
let a = execute(&t).convert();
3329+
let b = execute(&t).convert();
3330+
a.eq(&b);
3331+
let a = execute(&t).convert2();
3332+
let b = execute(&t).convert2();
3333+
a.eq(&b)
3334+
}
3335+
fn execute<T>(t: &T) -> T::Output
3336+
where
3337+
T: Request,
3338+
{
3339+
<T as Request>::output()
3340+
}
3341+
trait Convertable {
3342+
type TraitSelf: PartialEq<Self::TraitSelf>;
3343+
type AssocAsDefaultSelf: PartialEq;
3344+
fn convert(self) -> Self::AssocAsDefaultSelf;
3345+
fn convert2(self) -> Self::TraitSelf;
3346+
}
3347+
trait Request {
3348+
type Output;
3349+
fn output() -> Self::Output;
3350+
}
3351+
"#,
3352+
);
3353+
}
3354+
33193355
#[test]
33203356
fn bin_op_adt_with_rhs_primitive() {
33213357
check_infer_with_mismatches(

0 commit comments

Comments
 (0)