Rollup merge of #103827 - compiler-errors:rpitit-substs-compat, r=wesleywiser
Properly remap and check for substs compatibility in `confirm_impl_trait_in_trait_candidate` Fixes #103824
This commit is contained in:
commit
6c021cf07d
7 changed files with 127 additions and 4 deletions
|
@ -2187,7 +2187,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>(
|
||||
|
@ -2219,7 +2219,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>(
|
||||
|
@ -2248,11 +2251,27 @@ 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);
|
||||
let impl_fn_substs = translate_substs(
|
||||
selcx.infcx(),
|
||||
obligation.param_env,
|
||||
data.impl_def_id,
|
||||
impl_fn_substs,
|
||||
leaf_def.defining_node,
|
||||
);
|
||||
|
||||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue