@@ -2187,7 +2187,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
2187
2187
// Verify that the trait item and its implementation have compatible substs lists
2188
2188
fn check_substs_compatible < ' tcx > (
2189
2189
tcx : TyCtxt < ' tcx > ,
2190
- assoc_ty : & ty:: AssocItem ,
2190
+ assoc_item : & ty:: AssocItem ,
2191
2191
substs : ty:: SubstsRef < ' tcx > ,
2192
2192
) -> bool {
2193
2193
fn check_substs_compatible_inner < ' tcx > (
@@ -2219,7 +2219,10 @@ fn check_substs_compatible<'tcx>(
2219
2219
true
2220
2220
}
2221
2221
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)
2223
2226
}
2224
2227
2225
2228
fn confirm_impl_trait_in_trait_candidate < ' tcx > (
@@ -2248,11 +2251,27 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
2248
2251
} ;
2249
2252
}
2250
2253
2251
- let impl_fn_def_id = leaf_def. item . def_id ;
2252
2254
// Rebase from {trait}::{fn}::{opaque} to {impl}::{fn}::{opaque},
2253
2255
// since `data.substs` are the impl substs.
2254
2256
let impl_fn_substs =
2255
2257
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 ;
2256
2275
2257
2276
let cause = ObligationCause :: new (
2258
2277
obligation. cause . span ,
0 commit comments