From 60aeb8fa1a0432e50d880c8ba76cdea8f9344995 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 17 Mar 2022 17:08:43 +0100 Subject: [PATCH] Move fallback_bound_vars to the only place it's used now --- crates/hir_ty/src/lower.rs | 28 +++++++++++++++++++++++++- crates/hir_ty/src/method_resolution.rs | 28 +------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 0854d065483..41bb94c5d55 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -9,6 +9,8 @@ use std::{iter, sync::Arc}; use base_db::CrateId; +use chalk_ir::fold::Fold; +use chalk_ir::interner::HasInterner; use chalk_ir::{cast::Cast, fold::Shift, Mutability, Safety}; use hir_def::generics::TypeOrConstParamData; use hir_def::intern::Interned; @@ -36,7 +38,6 @@ use syntax::{ast, SmolStr}; use crate::consteval::{path_to_const, unknown_const_as_generic, unknown_const_usize, usize_const}; -use crate::method_resolution::fallback_bound_vars; use crate::utils::Generics; use crate::{all_super_traits, make_binders, Const, GenericArgData, ParamKind}; use crate::{ @@ -1701,3 +1702,28 @@ pub(crate) fn const_or_path_to_chalk( } } } + +/// 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 + HasInterner>( + 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::unknown_const(ty.clone()) + } else { + bound.shifted_in_from(binders).to_const(Interner, ty) + } + }, + ) +} diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 9120f80e2c5..1c939f3d8aa 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs @@ -6,7 +6,7 @@ use arrayvec::ArrayVec; use base_db::{CrateId, Edition}; -use chalk_ir::{cast::Cast, fold::Fold, interner::HasInterner, Mutability, UniverseIndex}; +use chalk_ir::{cast::Cast, Mutability, UniverseIndex}; use hir_def::{ item_scope::ItemScope, lang_item::LangItemTarget, nameres::DefMap, AssocItemId, BlockId, ConstId, FunctionId, GenericDefId, HasModule, ImplId, ItemContainerId, Lookup, ModuleDefId, @@ -18,7 +18,6 @@ use crate::{ autoderef::{self, AutoderefKind}, - consteval, db::HirDatabase, from_foreign_def_id, infer::{unify::InferenceTable, Adjust, Adjustment, AutoBorrow, OverloadedDeref, PointerCast}, @@ -1061,31 +1060,6 @@ fn is_valid_candidate( } } -/// This replaces any 'free' Bound vars in `s` (i.e. those with indices past -/// num_vars_to_keep) by `TyKind::Unknown`. -pub(crate) fn fallback_bound_vars + HasInterner>( - 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) - } - }, - ) -} - pub fn implements_trait( ty: &Canonical, db: &dyn HirDatabase,