Skip to content

Commit a317fa8

Browse files
committed
Auto merge of #15325 - HKalbasi:mir, r=flodiebold
Normalize expected ty in call arguments fix #15321 I'm not sure if we should do this, or add a normalize in the beginning of `infer_expr_inner`, or somewhere else. r? `@lowr`
2 parents 899dd84 + b7d91ca commit a317fa8

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

crates/hir-ty/src/infer/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,7 @@ impl InferenceContext<'_> {
16651665
// the parameter to coerce to the expected type (for example in
16661666
// `coerce_unsize_expected_type_4`).
16671667
let param_ty = self.normalize_associated_types_in(param_ty);
1668+
let expected_ty = self.normalize_associated_types_in(expected_ty);
16681669
let expected = Expectation::rvalue_hint(self, expected_ty);
16691670
// infer with the expected type we have...
16701671
let ty = self.infer_expr_inner(arg, &expected);

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

+44
Original file line numberDiff line numberDiff line change
@@ -4434,3 +4434,47 @@ fn test(v: S<i32>) {
44344434
"#,
44354435
);
44364436
}
4437+
4438+
#[test]
4439+
fn associated_type_in_argument() {
4440+
check(
4441+
r#"
4442+
trait A {
4443+
fn m(&self) -> i32;
4444+
}
4445+
4446+
fn x<T: B>(k: &<T as B>::Ty) {
4447+
k.m();
4448+
}
4449+
4450+
struct X;
4451+
struct Y;
4452+
4453+
impl A for X {
4454+
fn m(&self) -> i32 {
4455+
8
4456+
}
4457+
}
4458+
4459+
impl A for Y {
4460+
fn m(&self) -> i32 {
4461+
32
4462+
}
4463+
}
4464+
4465+
trait B {
4466+
type Ty: A;
4467+
}
4468+
4469+
impl B for u16 {
4470+
type Ty = X;
4471+
}
4472+
4473+
fn ttt() {
4474+
let inp = Y;
4475+
x::<u16>(&inp);
4476+
//^^^^ expected &X, got &Y
4477+
}
4478+
"#,
4479+
);
4480+
}

0 commit comments

Comments
 (0)