Check for substs compatibility for RPITITs
This commit is contained in:
parent
95a3a7277b
commit
a2037e3012
3 changed files with 44 additions and 3 deletions
|
@ -2192,7 +2192,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
|
|||
// Verify that the trait item and its implementation have compatible substs lists
|
||||
fn check_substs_compatible<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
assoc_ty: &ty::AssocItem,
|
||||
assoc_item: &ty::AssocItem,
|
||||
substs: ty::SubstsRef<'tcx>,
|
||||
) -> bool {
|
||||
fn check_substs_compatible_inner<'tcx>(
|
||||
|
@ -2224,7 +2224,10 @@ fn check_substs_compatible<'tcx>(
|
|||
true
|
||||
}
|
||||
|
||||
check_substs_compatible_inner(tcx, tcx.generics_of(assoc_ty.def_id), substs.as_slice())
|
||||
let generics = tcx.generics_of(assoc_item.def_id);
|
||||
// Chop off any additional substs (RPITIT) substs
|
||||
let substs = &substs[0..generics.count().min(substs.len())];
|
||||
check_substs_compatible_inner(tcx, generics, substs)
|
||||
}
|
||||
|
||||
fn confirm_impl_trait_in_trait_candidate<'tcx>(
|
||||
|
@ -2253,12 +2256,21 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>(
|
|||
};
|
||||
}
|
||||
|
||||
let impl_fn_def_id = leaf_def.item.def_id;
|
||||
// Rebase from {trait}::{fn}::{opaque} to {impl}::{fn}::{opaque},
|
||||
// since `data.substs` are the impl substs.
|
||||
let impl_fn_substs =
|
||||
obligation.predicate.substs.rebase_onto(tcx, tcx.parent(trait_fn_def_id), data.substs);
|
||||
|
||||
if !check_substs_compatible(tcx, &leaf_def.item, impl_fn_substs) {
|
||||
let err = tcx.ty_error_with_message(
|
||||
obligation.cause.span,
|
||||
"impl method and trait method have different parameters",
|
||||
);
|
||||
return Progress { term: err.into(), obligations };
|
||||
}
|
||||
|
||||
let impl_fn_def_id = leaf_def.item.def_id;
|
||||
|
||||
let cause = ObligationCause::new(
|
||||
obligation.cause.span,
|
||||
obligation.cause.body_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue