@@ -2192,7 +2192,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
21922192// Verify that the trait item and its implementation have compatible substs lists
21932193fn check_substs_compatible < ' tcx > (
21942194 tcx : TyCtxt < ' tcx > ,
2195- assoc_ty : & ty:: AssocItem ,
2195+ assoc_item : & ty:: AssocItem ,
21962196 substs : ty:: SubstsRef < ' tcx > ,
21972197) -> bool {
21982198 fn check_substs_compatible_inner < ' tcx > (
@@ -2224,7 +2224,10 @@ fn check_substs_compatible<'tcx>(
22242224 true
22252225 }
22262226
2227- check_substs_compatible_inner ( tcx, tcx. generics_of ( assoc_ty. def_id ) , substs. as_slice ( ) )
2227+ let generics = tcx. generics_of ( assoc_item. def_id ) ;
2228+ // Chop off any additional substs (RPITIT) substs
2229+ let substs = & substs[ 0 ..generics. count ( ) . min ( substs. len ( ) ) ] ;
2230+ check_substs_compatible_inner ( tcx, generics, substs)
22282231}
22292232
22302233fn confirm_impl_trait_in_trait_candidate < ' tcx > (
@@ -2253,12 +2256,21 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
22532256 } ;
22542257 }
22552258
2256- let impl_fn_def_id = leaf_def. item . def_id ;
22572259 // Rebase from {trait}::{fn}::{opaque} to {impl}::{fn}::{opaque},
22582260 // since `data.substs` are the impl substs.
22592261 let impl_fn_substs =
22602262 obligation. predicate . substs . rebase_onto ( tcx, tcx. parent ( trait_fn_def_id) , data. substs ) ;
22612263
2264+ if !check_substs_compatible ( tcx, & leaf_def. item , impl_fn_substs) {
2265+ let err = tcx. ty_error_with_message (
2266+ obligation. cause . span ,
2267+ "impl method and trait method have different parameters" ,
2268+ ) ;
2269+ return Progress { term : err. into ( ) , obligations } ;
2270+ }
2271+
2272+ let impl_fn_def_id = leaf_def. item . def_id ;
2273+
22622274 let cause = ObligationCause :: new (
22632275 obligation. cause . span ,
22642276 obligation. cause . body_id ,
0 commit comments