use arrayvec::ArrayVec;
use base_db::{CrateId, Edition};
-use chalk_ir::{cast::Cast, Mutability, UniverseIndex};
+use chalk_ir::{cast::Cast, fold::Fold, interner::HasInterner, Mutability, UniverseIndex};
use hir_def::{
item_scope::ItemScope, lang_item::LangItemTarget, nameres::DefMap, AssocItemId, BlockId,
ConstId, FunctionId, GenericDefId, HasModule, ImplId, ItemContainerId, Lookup, ModuleDefId,
primitive::{self, FloatTy, IntTy, UintTy},
static_lifetime,
utils::all_super_traits,
- AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, ForeignDefId, InEnvironment, Interner,
- Scalar, Substitution, TraitEnvironment, TraitRefExt, Ty, TyBuilder, TyExt, TyKind,
+ AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, ForeignDefId, GenericArgData,
+ InEnvironment, Interner, Scalar, Substitution, TraitEnvironment, TraitRefExt, Ty, TyBuilder,
+ TyExt, TyKind,
};
/// This is used as a key for indexing impls.
impls.collect_def_map(db, &crate_def_map);
impls.shrink_to_fit();
- return Arc::new(impls);
+ Arc::new(impls)
}
pub(crate) fn inherent_impls_in_block_query(
impls.shrink_to_fit();
return Some(Arc::new(impls));
}
- return None;
+ None
}
fn shrink_to_fit(&mut self) {
iterate_method_candidates_for_self_ty(
ty,
db,
- env.clone(),
+ env,
traits_in_scope,
visible_from_module,
name,
iterate_method_candidates_by_receiver(
receiver_ty,
first_adjustment.clone(),
- &rest,
+ rest,
db,
env.clone(),
traits_in_scope,
first_adjustment.with_autoref(Mutability::Mut),
deref_chain,
db,
- env.clone(),
+ env,
traits_in_scope,
visible_from_module,
name,
// already happens in `is_valid_candidate` above; if not, we
// check it here
if receiver_ty.is_none()
- && inherent_impl_substs(db, env.clone(), impl_def, &self_ty).is_none()
+ && inherent_impl_substs(db, env.clone(), impl_def, self_ty).is_none()
{
cov_mark::hit!(impl_self_type_match_without_receiver);
continue;
.build();
let self_ty_with_vars = db.impl_self_ty(impl_id).substitute(Interner, &vars);
let mut kinds = self_ty.binders.interned().to_vec();
- kinds.extend(
- iter::repeat(chalk_ir::WithKind::new(
- chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
- UniverseIndex::ROOT,
- ))
- .take(vars.len(Interner)),
- );
+ kinds.extend(vars.iter(Interner).map(|x| {
+ let kind = match x.data(Interner) {
+ GenericArgData::Ty(_) => chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
+ GenericArgData::Const(c) => chalk_ir::VariableKind::Const(c.data(Interner).ty.clone()),
+ GenericArgData::Lifetime(_) => chalk_ir::VariableKind::Lifetime,
+ };
+ chalk_ir::WithKind::new(kind, UniverseIndex::ROOT)
+ }));
let tys = Canonical {
binders: CanonicalVarKinds::from_iter(Interner, kinds),
value: (self_ty_with_vars, self_ty.value.clone()),
// Unknown, and in that case we want the result to contain Unknown in those
// places again.
let suffix =
- Substitution::from_iter(Interner, substs.iter(Interner).cloned().skip(self_ty_vars));
+ Substitution::from_iter(Interner, substs.iter(Interner).skip(self_ty_vars).cloned());
Some(fallback_bound_vars(suffix, self_ty_vars))
}
/// 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 {
- 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)
- }
- })
+pub(crate) fn fallback_bound_vars<T: Fold<Interner> + HasInterner<Interner = Interner>>(
+ s: T,
+ num_vars_to_keep: usize,
+) -> T::Result {
+ 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)
+ }
+ },
+ |ty, bound, binders| {
+ if bound.index >= num_vars_to_keep && bound.debruijn == DebruijnIndex::INNERMOST {
+ consteval::usize_const(None)
+ } else {
+ bound.shifted_in_from(binders).to_const(Interner, ty)
+ }
+ },
+ )
}
fn transform_receiver_ty(
env: Arc<TraitEnvironment>,
trait_: TraitId,
) -> bool {
- let goal = generic_implements_goal(db, env.clone(), trait_, &ty);
+ let goal = generic_implements_goal(db, env.clone(), trait_, ty);
let solution = db.trait_solve(env.krate, goal.cast(Interner));
solution.is_some()
env: Arc<TraitEnvironment>,
trait_: TraitId,
) -> bool {
- let goal = generic_implements_goal(db, env.clone(), trait_, &ty);
+ let goal = generic_implements_goal(db, env.clone(), trait_, ty);
let solution = db.trait_solve(env.krate, goal.cast(Interner));
matches!(solution, Some(crate::Solution::Unique(_)))
.push(self_ty.value.clone())
.fill_with_bound_vars(DebruijnIndex::INNERMOST, kinds.len())
.build();
- kinds.extend(
- iter::repeat(chalk_ir::WithKind::new(
- chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General),
- UniverseIndex::ROOT,
- ))
- .take(trait_ref.substitution.len(Interner) - 1),
- );
+ kinds.extend(trait_ref.substitution.iter(Interner).skip(1).map(|x| {
+ let vk = match x.data(Interner) {
+ chalk_ir::GenericArgData::Ty(_) => {
+ chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General)
+ }
+ chalk_ir::GenericArgData::Lifetime(_) => chalk_ir::VariableKind::Lifetime,
+ chalk_ir::GenericArgData::Const(c) => {
+ chalk_ir::VariableKind::Const(c.data(Interner).ty.clone())
+ }
+ };
+ chalk_ir::WithKind::new(vk, UniverseIndex::ROOT)
+ }));
let obligation = trait_ref.cast(Interner);
Canonical {
binders: CanonicalVarKinds::from_iter(Interner, kinds),