@@ -2192,7 +2192,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
2192
2192
// Verify that the trait item and its implementation have compatible substs lists
2193
2193
fn check_substs_compatible < ' tcx > (
2194
2194
tcx : TyCtxt < ' tcx > ,
2195
- assoc_ty : & ty:: AssocItem ,
2195
+ assoc_item : & ty:: AssocItem ,
2196
2196
substs : ty:: SubstsRef < ' tcx > ,
2197
2197
) -> bool {
2198
2198
fn check_substs_compatible_inner < ' tcx > (
@@ -2224,7 +2224,10 @@ fn check_substs_compatible<'tcx>(
2224
2224
true
2225
2225
}
2226
2226
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)
2228
2231
}
2229
2232
2230
2233
fn confirm_impl_trait_in_trait_candidate < ' tcx > (
@@ -2253,12 +2256,21 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
2253
2256
} ;
2254
2257
}
2255
2258
2256
- let impl_fn_def_id = leaf_def. item . def_id ;
2257
2259
// Rebase from {trait}::{fn}::{opaque} to {impl}::{fn}::{opaque},
2258
2260
// since `data.substs` are the impl substs.
2259
2261
let impl_fn_substs =
2260
2262
obligation. predicate . substs . rebase_onto ( tcx, tcx. parent ( trait_fn_def_id) , data. substs ) ;
2261
2263
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
+
2262
2274
let cause = ObligationCause :: new (
2263
2275
obligation. cause . span ,
2264
2276
obligation. cause . body_id ,
0 commit comments