Replace some fold calls

This commit is contained in:
Florian Diebold 2021-04-07 21:26:37 +02:00
parent b25b147e86
commit caee3b6c2d
4 changed files with 53 additions and 47 deletions

View file

@ -6,7 +6,11 @@ use std::{iter, sync::Arc};
use arrayvec::ArrayVec;
use base_db::CrateId;
use chalk_ir::{cast::Cast, Mutability, UniverseIndex};
use chalk_ir::{
cast::Cast,
fold::{Fold, Folder},
Fallible, Mutability, UniverseIndex,
};
use hir_def::{
lang_item::LangItemTarget, nameres::DefMap, AssocContainerId, AssocItemId, FunctionId,
GenericDefId, HasModule, ImplId, Lookup, ModuleId, TraitId,
@ -21,7 +25,7 @@ use crate::{
primitive::{self, FloatTy, IntTy, UintTy},
static_lifetime,
utils::all_super_traits,
AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId,
AdtId, BoundVar, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId,
InEnvironment, Interner, Scalar, Substitution, TraitEnvironment, TraitRefExt, Ty, TyBuilder,
TyExt, TyKind, TypeWalk,
};
@ -757,20 +761,13 @@ pub(crate) fn inherent_impl_substs(
/// This replaces any 'free' Bound vars in `s` (i.e. those with indices past
/// num_vars_to_keep) by `TyKind::Unknown`.
fn fallback_bound_vars(s: Substitution, num_vars_to_keep: usize) -> Substitution {
s.fold_binders(
&mut |ty, binders| {
if let TyKind::BoundVar(bound) = ty.kind(&Interner) {
if bound.index >= num_vars_to_keep && bound.debruijn >= binders {
TyKind::Error.intern(&Interner)
} else {
ty
}
} else {
ty
}
},
DebruijnIndex::INNERMOST,
)
crate::fold_free_vars(s, |bound, binders| {
if bound.index >= num_vars_to_keep && bound.debruijn == DebruijnIndex::INNERMOST {
TyKind::Error.intern(&Interner)
} else {
bound.shifted_in_from(binders).to_ty(&Interner)
}
})
}
fn transform_receiver_ty(