aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/builder.rs5
-rw-r--r--crates/hir_ty/src/display.rs3
-rw-r--r--crates/hir_ty/src/lib.rs8
-rw-r--r--crates/hir_ty/src/lower.rs7
4 files changed, 11 insertions, 12 deletions
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<()> {
99 } 99 }
100 } 100 }
101 101
102 pub fn type_params_subst(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substitution {
103 let params = generics(db.upcast(), def.into());
104 params.type_params_subst(db)
105 }
106
102 pub fn subst_for_def(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> TyBuilder<()> { 107 pub fn subst_for_def(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> TyBuilder<()> {
103 let def = def.into(); 108 let def = def.into();
104 let params = generics(db.upcast(), def); 109 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::{
19 db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, 19 db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive,
20 to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, 20 to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy,
21 CallableDefId, CallableSig, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, OpaqueTy, 21 CallableDefId, CallableSig, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, OpaqueTy,
22 ProjectionTy, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, 22 ProjectionTy, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, WhereClause,
23 WhereClause,
24}; 23};
25 24
26pub struct HirFormatter<'a> { 25pub 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 {
462 ) -> Self { 462 ) -> Self {
463 Substitution(elements.into_iter().casted(interner).collect()) 463 Substitution(elements.into_iter().casted(interner).collect())
464 } 464 }
465
466 /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`).
467 pub fn type_params(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substitution {
468 let params = generics(db.upcast(), def.into());
469 params.type_params_subst(db)
470 }
471} 465}
472 466
473/// Return an index of a parameter in the generic type parameter list by it's id. 467/// Return an index of a parameter in the generic type parameter list by it's id.
@@ -944,7 +938,7 @@ impl Ty {
944 let param_data = &generic_params.types[id.local_id]; 938 let param_data = &generic_params.types[id.local_id];
945 match param_data.provenance { 939 match param_data.provenance {
946 hir_def::generics::TypeParamProvenance::ArgumentImplTrait => { 940 hir_def::generics::TypeParamProvenance::ArgumentImplTrait => {
947 let substs = Substitution::type_params(db, id.parent); 941 let substs = TyBuilder::type_params_subst(db, id.parent);
948 let predicates = db 942 let predicates = db
949 .generic_predicates(id.parent) 943 .generic_predicates(id.parent)
950 .into_iter() 944 .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> {
470 TypeParamLoweringMode::Placeholder => { 470 TypeParamLoweringMode::Placeholder => {
471 // if we're lowering to placeholders, we have to put 471 // if we're lowering to placeholders, we have to put
472 // them in now 472 // them in now
473 let s = Substitution::type_params( 473 let generics = generics(
474 self.db, 474 self.db.upcast(),
475 self.resolver.generic_def().expect( 475 self.resolver.generic_def().expect(
476 "there should be generics if there's a generic param", 476 "there should be generics if there's a generic param",
477 ), 477 ),
478 ); 478 );
479 let s = generics.type_params_subst(self.db);
479 t.substitution.clone().subst_bound_vars(&s) 480 t.substitution.clone().subst_bound_vars(&s)
480 } 481 }
481 TypeParamLoweringMode::Variable => t.substitution.clone(), 482 TypeParamLoweringMode::Variable => t.substitution.clone(),
@@ -963,7 +964,7 @@ pub(crate) fn trait_environment_query(
963 // function default implementations (and hypothetical code 964 // function default implementations (and hypothetical code
964 // inside consts or type aliases) 965 // inside consts or type aliases)
965 cov_mark::hit!(trait_self_implements_self); 966 cov_mark::hit!(trait_self_implements_self);
966 let substs = Substitution::type_params(db, trait_id); 967 let substs = TyBuilder::type_params_subst(db, trait_id);
967 let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs }; 968 let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs };
968 let pred = WhereClause::Implemented(trait_ref); 969 let pred = WhereClause::Implemented(trait_ref);
969 let program_clause: chalk_ir::ProgramClause<Interner> = pred.to_chalk(db).cast(&Interner); 970 let program_clause: chalk_ir::ProgramClause<Interner> = pred.to_chalk(db).cast(&Interner);