Skip to content

Commit

Permalink
Auto merge of rust-lang#12336 - bitgaoshu:mismatch, r=flodiebold
Browse files Browse the repository at this point in the history
fix: rust-lang#12267  type-mismatch when using equals w/ a trait bound
  • Loading branch information
bors committed May 31, 2022
2 parents f65d734 + 7c5e972 commit c2099fe
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
6 changes: 4 additions & 2 deletions crates/hir-ty/src/chalk_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
38 changes: 37 additions & 1 deletion crates/hir-ty/src/tests/traits.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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: 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) -> T::Output
where
T: Request,
{
<T as Request>::output()
}
trait Convertable {
type TraitSelf: PartialEq<Self::TraitSelf>;
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(
Expand Down

0 comments on commit c2099fe

Please sign in to comment.