From ebdfc932e74ff11c8c14c513614212b7c07bf400 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 4 Apr 2021 13:16:16 +0200 Subject: Replace Substitution::type_params --- crates/hir_ty/src/builder.rs | 5 +++++ crates/hir_ty/src/display.rs | 3 +-- crates/hir_ty/src/lib.rs | 8 +------- crates/hir_ty/src/lower.rs | 7 ++++--- 4 files changed, 11 insertions(+), 12 deletions(-) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/builder.rs b/crates/hir_ty/src/builder.rs index ba158a749..4d3b4eade 100644 --- a/crates/hir_ty/src/builder.rs +++ b/crates/hir_ty/src/builder.rs @@ -99,6 +99,11 @@ impl TyBuilder<()> { } } + pub fn type_params_subst(db: &dyn HirDatabase, def: impl Into) -> Substitution { + let params = generics(db.upcast(), def.into()); + params.type_params_subst(db) + } + pub fn subst_for_def(db: &dyn HirDatabase, def: impl Into) -> TyBuilder<()> { let def = def.into(); let params = generics(db.upcast(), def); diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 39e0b328d..385bd9405 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -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> { diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 6d6443ca3..a8c87eadf 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -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) -> 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() diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index f9a721fdf..214655807 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -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 = pred.to_chalk(db).cast(&Interner); -- cgit v1.2.3