Substitution::prefix -> subst_prefix

I probably want to get rid of this function completely later.
This commit is contained in:
Florian Diebold 2021-04-05 21:56:40 +02:00
parent 2a83645e1b
commit b67148daea
4 changed files with 15 additions and 11 deletions

View file

@ -55,6 +55,7 @@ use hir_ty::{
autoderef, could_unify,
method_resolution::{self, TyFingerprint},
primitive::UintTy,
subst_prefix,
traits::FnTrait,
AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast,
DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Solution,
@ -1503,7 +1504,7 @@ impl TypeParam {
let krate = self.id.parent.module(db.upcast()).krate();
let ty = params.get(local_idx)?.clone();
let subst = TyBuilder::type_params_subst(db, self.id.parent);
let ty = ty.substitute(&Interner, &subst.prefix(local_idx));
let ty = ty.substitute(&Interner, &subst_prefix(&subst, local_idx));
Some(Type::new_with_resolver_inner(db, krate, &resolver, ty))
}
}

View file

@ -19,7 +19,7 @@ use hir_expand::name::Name;
use crate::{
db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx,
lt_from_placeholder_idx, primitive, to_assoc_type_id, traits::chalk::from_chalk,
lt_from_placeholder_idx, primitive, subst_prefix, to_assoc_type_id, traits::chalk::from_chalk,
utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, DomainGoal, GenericArg,
ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives, Mutability, OpaqueTy,
ProjectionTy, ProjectionTyExt, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind,
@ -484,9 +484,11 @@ impl HirDisplay for Ty {
default_from = i + 1;
}
(_, Some(default_parameter)) => {
let actual_default = default_parameter
.clone()
.substitute(&Interner, &parameters.prefix(i));
let actual_default =
default_parameter.clone().substitute(
&Interner,
&subst_prefix(parameters, i),
);
if parameter.assert_ty_ref(&Interner) != &actual_default
{
default_from = i + 1;

View file

@ -964,8 +964,10 @@ impl<'a> InferenceContext<'a> {
if let AssocContainerId::TraitId(trait_) = f.lookup(self.db.upcast()).container
{
// construct a TraitRef
let substs =
parameters.prefix(generics(self.db.upcast(), trait_.into()).len());
let substs = crate::subst_prefix(
&*parameters,
generics(self.db.upcast(), trait_.into()).len(),
);
self.push_obligation(
TraitRef { trait_id: to_chalk_trait_id(trait_), substitution: substs }
.cast(&Interner),

View file

@ -75,10 +75,9 @@ pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
pub type FnSig = chalk_ir::FnSig<Interner>;
impl Substitution {
pub fn prefix(&self, n: usize) -> Substitution {
Substitution::intern(self.interned()[..std::cmp::min(self.len(&Interner), n)].into())
}
// FIXME: get rid of this
pub fn subst_prefix(s: &Substitution, n: usize) -> Substitution {
Substitution::intern(s.interned()[..std::cmp::min(s.len(&Interner), n)].into())
}
/// Return an index of a parameter in the generic type parameter list by it's id.