Don't substitute a GAT that has mismatched generics in OpaqueTypeCollector
This commit is contained in:
parent
38b44eb233
commit
5344ed23fa
6 changed files with 144 additions and 75 deletions
|
@ -1,5 +1,6 @@
|
|||
//! Code for projecting associated types out of trait references.
|
||||
|
||||
use super::check_substs_compatible;
|
||||
use super::specialization_graph;
|
||||
use super::translate_substs;
|
||||
use super::util;
|
||||
|
@ -2378,47 +2379,6 @@ 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_item: ty::AssocItem,
|
||||
substs: ty::SubstsRef<'tcx>,
|
||||
) -> bool {
|
||||
fn check_substs_compatible_inner<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
generics: &'tcx ty::Generics,
|
||||
args: &'tcx [ty::GenericArg<'tcx>],
|
||||
) -> bool {
|
||||
if generics.count() != args.len() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let (parent_args, own_args) = args.split_at(generics.parent_count);
|
||||
|
||||
if let Some(parent) = generics.parent
|
||||
&& let parent_generics = tcx.generics_of(parent)
|
||||
&& !check_substs_compatible_inner(tcx, parent_generics, parent_args) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (param, arg) in std::iter::zip(&generics.params, own_args) {
|
||||
match (¶m.kind, arg.unpack()) {
|
||||
(ty::GenericParamDefKind::Type { .. }, ty::GenericArgKind::Type(_))
|
||||
| (ty::GenericParamDefKind::Lifetime, ty::GenericArgKind::Lifetime(_))
|
||||
| (ty::GenericParamDefKind::Const { .. }, ty::GenericArgKind::Const(_)) => {}
|
||||
_ => return false,
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
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>(
|
||||
selcx: &mut SelectionContext<'_, 'tcx>,
|
||||
obligation: &ProjectionTyObligation<'tcx>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue