Replace Substitution::type_params

This commit is contained in:
Florian Diebold 2021-04-04 13:16:16 +02:00
parent a4d7bdf1c8
commit ebdfc932e7
6 changed files with 15 additions and 16 deletions

View file

@ -99,6 +99,11 @@ impl TyBuilder<()> {
}
}
pub fn type_params_subst(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substitution {
let params = generics(db.upcast(), def.into());
params.type_params_subst(db)
}
pub fn subst_for_def(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> TyBuilder<()> {
let def = def.into();
let params = generics(db.upcast(), def);

View file

@ -19,8 +19,7 @@ use crate::{
db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive,
to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy,
CallableDefId, CallableSig, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, OpaqueTy,
ProjectionTy, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind,
WhereClause,
ProjectionTy, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, WhereClause,
};
pub struct HirFormatter<'a> {

View file

@ -462,12 +462,6 @@ impl Substitution {
) -> Self {
Substitution(elements.into_iter().casted(interner).collect())
}
/// Return Substs that replace each parameter by itself (i.e. `Ty::Param`).
pub fn type_params(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substitution {
let params = generics(db.upcast(), def.into());
params.type_params_subst(db)
}
}
/// Return an index of a parameter in the generic type parameter list by it's id.
@ -944,7 +938,7 @@ impl Ty {
let param_data = &generic_params.types[id.local_id];
match param_data.provenance {
hir_def::generics::TypeParamProvenance::ArgumentImplTrait => {
let substs = Substitution::type_params(db, id.parent);
let substs = TyBuilder::type_params_subst(db, id.parent);
let predicates = db
.generic_predicates(id.parent)
.into_iter()

View file

@ -470,12 +470,13 @@ impl<'a> TyLoweringContext<'a> {
TypeParamLoweringMode::Placeholder => {
// if we're lowering to placeholders, we have to put
// them in now
let s = Substitution::type_params(
self.db,
let generics = generics(
self.db.upcast(),
self.resolver.generic_def().expect(
"there should be generics if there's a generic param",
),
);
let s = generics.type_params_subst(self.db);
t.substitution.clone().subst_bound_vars(&s)
}
TypeParamLoweringMode::Variable => t.substitution.clone(),
@ -963,7 +964,7 @@ pub(crate) fn trait_environment_query(
// function default implementations (and hypothetical code
// inside consts or type aliases)
cov_mark::hit!(trait_self_implements_self);
let substs = Substitution::type_params(db, trait_id);
let substs = TyBuilder::type_params_subst(db, trait_id);
let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs };
let pred = WhereClause::Implemented(trait_ref);
let program_clause: chalk_ir::ProgramClause<Interner> = pred.to_chalk(db).cast(&Interner);