@@ -2187,7 +2187,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
21872187// Verify that the trait item and its implementation have compatible substs lists
21882188fn check_substs_compatible < ' tcx > (
21892189 tcx : TyCtxt < ' tcx > ,
2190- assoc_ty : & ty:: AssocItem ,
2190+ assoc_item : & ty:: AssocItem ,
21912191 substs : ty:: SubstsRef < ' tcx > ,
21922192) -> bool {
21932193 fn check_substs_compatible_inner < ' tcx > (
@@ -2219,7 +2219,10 @@ fn check_substs_compatible<'tcx>(
22192219 true
22202220 }
22212221
2222- check_substs_compatible_inner ( tcx, tcx. generics_of ( assoc_ty. def_id ) , substs. as_slice ( ) )
2222+ let generics = tcx. generics_of ( assoc_item. def_id ) ;
2223+ // Chop off any additional substs (RPITIT) substs
2224+ let substs = & substs[ 0 ..generics. count ( ) . min ( substs. len ( ) ) ] ;
2225+ check_substs_compatible_inner ( tcx, generics, substs)
22232226}
22242227
22252228fn confirm_impl_trait_in_trait_candidate < ' tcx > (
@@ -2248,11 +2251,27 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
22482251 } ;
22492252 }
22502253
2251- let impl_fn_def_id = leaf_def. item . def_id ;
22522254 // Rebase from {trait}::{fn}::{opaque} to {impl}::{fn}::{opaque},
22532255 // since `data.substs` are the impl substs.
22542256 let impl_fn_substs =
22552257 obligation. predicate . substs . rebase_onto ( tcx, tcx. parent ( trait_fn_def_id) , data. substs ) ;
2258+ let impl_fn_substs = translate_substs (
2259+ selcx. infcx ( ) ,
2260+ obligation. param_env ,
2261+ data. impl_def_id ,
2262+ impl_fn_substs,
2263+ leaf_def. defining_node ,
2264+ ) ;
2265+
2266+ if !check_substs_compatible ( tcx, & leaf_def. item , impl_fn_substs) {
2267+ let err = tcx. ty_error_with_message (
2268+ obligation. cause . span ,
2269+ "impl method and trait method have different parameters" ,
2270+ ) ;
2271+ return Progress { term : err. into ( ) , obligations } ;
2272+ }
2273+
2274+ let impl_fn_def_id = leaf_def. item . def_id ;
22562275
22572276 let cause = ObligationCause :: new (
22582277 obligation. cause . span ,
0 commit comments