File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -1665,6 +1665,7 @@ impl InferenceContext<'_> {
1665
1665
// the parameter to coerce to the expected type (for example in
1666
1666
// `coerce_unsize_expected_type_4`).
1667
1667
let param_ty = self . normalize_associated_types_in ( param_ty) ;
1668
+ let expected_ty = self . normalize_associated_types_in ( expected_ty) ;
1668
1669
let expected = Expectation :: rvalue_hint ( self , expected_ty) ;
1669
1670
// infer with the expected type we have...
1670
1671
let ty = self . infer_expr_inner ( arg, & expected) ;
Original file line number Diff line number Diff line change @@ -4434,3 +4434,47 @@ fn test(v: S<i32>) {
4434
4434
"# ,
4435
4435
) ;
4436
4436
}
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
+ }
You can’t perform that action at this time.
0 commit comments