@@ -23,6 +23,7 @@ use crate::ty::subst::{Subst, InternalSubsts};
23
23
use crate :: ty:: { self , ToPredicate , ToPolyTraitRef , Ty , TyCtxt } ;
24
24
use crate :: ty:: fold:: { TypeFoldable , TypeFolder } ;
25
25
use crate :: util:: common:: FN_OUTPUT_NAME ;
26
+ use syntax_pos:: DUMMY_SP ;
26
27
27
28
/// Depending on the stage of compilation, we want projection to be
28
29
/// more or less conservative.
@@ -1437,11 +1438,14 @@ fn confirm_impl_candidate<'cx, 'tcx>(
1437
1438
obligation : & ProjectionTyObligation < ' tcx > ,
1438
1439
impl_vtable : VtableImplData < ' tcx , PredicateObligation < ' tcx > > ,
1439
1440
) -> Progress < ' tcx > {
1441
+ let tcx = selcx. tcx ( ) ;
1442
+
1440
1443
let VtableImplData { impl_def_id, substs, nested } = impl_vtable;
1444
+ let assoc_item_id = obligation. predicate . item_def_id ;
1445
+ let trait_def_id = tcx. trait_id_of_impl ( impl_def_id) . unwrap ( ) ;
1441
1446
1442
- let tcx = selcx. tcx ( ) ;
1443
1447
let param_env = obligation. param_env ;
1444
- let assoc_ty = assoc_ty_def ( selcx, impl_def_id, obligation . predicate . item_def_id ) ;
1448
+ let assoc_ty = assoc_ty_def ( selcx, impl_def_id, assoc_item_id ) ;
1445
1449
1446
1450
if !assoc_ty. item . defaultness . has_value ( ) {
1447
1451
// This means that the impl is missing a definition for the
@@ -1456,16 +1460,28 @@ fn confirm_impl_candidate<'cx, 'tcx>(
1456
1460
obligations : nested,
1457
1461
} ;
1458
1462
}
1463
+ let substs = obligation. predicate . substs . rebase_onto ( tcx, trait_def_id, substs) ;
1459
1464
let substs = translate_substs ( selcx. infcx ( ) , param_env, impl_def_id, substs, assoc_ty. node ) ;
1460
1465
let ty = if let ty:: AssocKind :: OpaqueTy = assoc_ty. item . kind {
1461
1466
let item_substs = InternalSubsts :: identity_for_item ( tcx, assoc_ty. item . def_id ) ;
1462
1467
tcx. mk_opaque ( assoc_ty. item . def_id , item_substs)
1463
1468
} else {
1464
1469
tcx. type_of ( assoc_ty. item . def_id )
1465
1470
} ;
1466
- Progress {
1467
- ty : ty. subst ( tcx, substs) ,
1468
- obligations : nested,
1471
+ if substs. len ( ) != tcx. generics_of ( assoc_ty. item . def_id ) . count ( ) {
1472
+ tcx. sess . delay_span_bug (
1473
+ DUMMY_SP ,
1474
+ "impl item and trait item have different parameter counts" ,
1475
+ ) ;
1476
+ Progress {
1477
+ ty : tcx. types . err ,
1478
+ obligations : nested,
1479
+ }
1480
+ } else {
1481
+ Progress {
1482
+ ty : ty. subst ( tcx, substs) ,
1483
+ obligations : nested,
1484
+ }
1469
1485
}
1470
1486
}
1471
1487
0 commit comments