Uplift and start using check_args_compatible more liberally
This commit is contained in:
@@ -344,46 +344,6 @@ pub enum TupleArgumentsFlag {
|
||||
No,
|
||||
}
|
||||
|
||||
// Verify that the trait item and its implementation have compatible args lists
|
||||
pub fn check_args_compatible<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
assoc_item: ty::AssocItem,
|
||||
args: ty::GenericArgsRef<'tcx>,
|
||||
) -> bool {
|
||||
fn check_args_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_args_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);
|
||||
check_args_compatible_inner(tcx, generics, args)
|
||||
}
|
||||
|
||||
/// Executes `f` on `value` after replacing all escaping bound variables with placeholders
|
||||
/// and then replaces these placeholders with the original bound variables in the result.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user