@@ -23,6 +23,7 @@ use crate::ty::subst::{Subst, InternalSubsts};
2323use crate :: ty:: { self , ToPredicate , ToPolyTraitRef , Ty , TyCtxt } ;
2424use crate :: ty:: fold:: { TypeFoldable , TypeFolder } ;
2525use crate :: util:: common:: FN_OUTPUT_NAME ;
26+ use syntax_pos:: DUMMY_SP ;
2627
2728/// Depending on the stage of compilation, we want projection to be
2829/// more or less conservative.
@@ -1437,11 +1438,14 @@ fn confirm_impl_candidate<'cx, 'tcx>(
14371438 obligation : & ProjectionTyObligation < ' tcx > ,
14381439 impl_vtable : VtableImplData < ' tcx , PredicateObligation < ' tcx > > ,
14391440) -> Progress < ' tcx > {
1441+ let tcx = selcx. tcx ( ) ;
1442+
14401443 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 ( ) ;
14411446
1442- let tcx = selcx. tcx ( ) ;
14431447 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 ) ;
14451449
14461450 if !assoc_ty. item . defaultness . has_value ( ) {
14471451 // This means that the impl is missing a definition for the
@@ -1456,16 +1460,28 @@ fn confirm_impl_candidate<'cx, 'tcx>(
14561460 obligations : nested,
14571461 } ;
14581462 }
1463+ let substs = obligation. predicate . substs . rebase_onto ( tcx, trait_def_id, substs) ;
14591464 let substs = translate_substs ( selcx. infcx ( ) , param_env, impl_def_id, substs, assoc_ty. node ) ;
14601465 let ty = if let ty:: AssocKind :: OpaqueTy = assoc_ty. item . kind {
14611466 let item_substs = InternalSubsts :: identity_for_item ( tcx, assoc_ty. item . def_id ) ;
14621467 tcx. mk_opaque ( assoc_ty. item . def_id , item_substs)
14631468 } else {
14641469 tcx. type_of ( assoc_ty. item . def_id )
14651470 } ;
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+ }
14691485 }
14701486}
14711487
0 commit comments