Skip to content

Commit

Permalink
Move fallback_bound_vars to the only place it's used now
Browse files Browse the repository at this point in the history
  • Loading branch information
flodiebold committed Mar 17, 2022
1 parent 9ea2e0b commit 60aeb8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
28 changes: 27 additions & 1 deletion crates/hir_ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::cell::{Cell, RefCell};
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;
Expand Down Expand Up @@ -36,7 +38,6 @@ use stdx::{impl_from, never};
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::{
Expand Down Expand Up @@ -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<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::unknown_const(ty.clone())
} else {
bound.shifted_in_from(binders).to_const(Interner, ty)
}
},
)
}
28 changes: 1 addition & 27 deletions crates/hir_ty/src/method_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{iter, ops::ControlFlow, sync::Arc};

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,
Expand All @@ -18,7 +18,6 @@ use stdx::never;

use crate::{
autoderef::{self, AutoderefKind},
consteval,
db::HirDatabase,
from_foreign_def_id,
infer::{unify::InferenceTable, Adjust, Adjustment, AutoBorrow, OverloadedDeref, PointerCast},
Expand Down Expand Up @@ -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<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)
}
},
)
}

pub fn implements_trait(
ty: &Canonical<Ty>,
db: &dyn HirDatabase,
Expand Down

0 comments on commit 60aeb8f

Please sign in to comment.