diff options
author | Florian Diebold <[email protected]> | 2021-04-03 21:18:02 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-04-04 12:16:38 +0100 |
commit | 5d2b488aeb17410aec3b89eac69038c51f332448 (patch) | |
tree | 30ef50eb5dc4e8c572c6bec969ce96b3ed2f3e68 /crates/hir_ty/src/lib.rs | |
parent | 77333a571ffb401a6765bbc80dea082ad08238d9 (diff) |
Replace remaining uses of Substitution::build_for_def
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r-- | crates/hir_ty/src/lib.rs | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index e586d73d8..75bf8bcd9 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -28,7 +28,10 @@ mod chalk_ext; | |||
28 | use std::{iter, mem, sync::Arc}; | 28 | use std::{iter, mem, sync::Arc}; |
29 | 29 | ||
30 | use base_db::salsa; | 30 | use base_db::salsa; |
31 | use chalk_ir::cast::{CastTo, Caster}; | 31 | use chalk_ir::{ |
32 | cast::{CastTo, Caster}, | ||
33 | interner::HasInterner, | ||
34 | }; | ||
32 | use hir_def::{ | 35 | use hir_def::{ |
33 | builtin_type::BuiltinType, expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId, | 36 | builtin_type::BuiltinType, expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId, |
34 | GenericDefId, HasModule, LifetimeParamId, Lookup, TraitId, TypeAliasId, TypeParamId, | 37 | GenericDefId, HasModule, LifetimeParamId, Lookup, TraitId, TypeAliasId, TypeParamId, |
@@ -490,13 +493,6 @@ impl Substitution { | |||
490 | ) | 493 | ) |
491 | } | 494 | } |
492 | 495 | ||
493 | pub fn build_for_def(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> SubstsBuilder { | ||
494 | let def = def.into(); | ||
495 | let params = generics(db.upcast(), def); | ||
496 | let param_count = params.len(); | ||
497 | Substitution::builder(param_count) | ||
498 | } | ||
499 | |||
500 | pub(crate) fn build_for_generics(generic_params: &Generics) -> SubstsBuilder { | 496 | pub(crate) fn build_for_generics(generic_params: &Generics) -> SubstsBuilder { |
501 | Substitution::builder(generic_params.len()) | 497 | Substitution::builder(generic_params.len()) |
502 | } | 498 | } |
@@ -894,6 +890,18 @@ impl TyBuilder<()> { | |||
894 | } | 890 | } |
895 | } | 891 | } |
896 | } | 892 | } |
893 | |||
894 | pub fn subst_for_def(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> TyBuilder<()> { | ||
895 | let def = def.into(); | ||
896 | let params = generics(db.upcast(), def); | ||
897 | let param_count = params.len(); | ||
898 | TyBuilder::new((), param_count) | ||
899 | } | ||
900 | |||
901 | pub fn build(self) -> Substitution { | ||
902 | let ((), subst) = self.build_internal(); | ||
903 | subst | ||
904 | } | ||
897 | } | 905 | } |
898 | 906 | ||
899 | impl TyBuilder<hir_def::AdtId> { | 907 | impl TyBuilder<hir_def::AdtId> { |
@@ -956,6 +964,28 @@ impl TyBuilder<TypeAliasId> { | |||
956 | } | 964 | } |
957 | } | 965 | } |
958 | 966 | ||
967 | impl<T: TypeWalk + HasInterner<Interner = Interner>> TyBuilder<Binders<T>> { | ||
968 | fn subst_binders(b: Binders<T>) -> Self { | ||
969 | let param_count = b.num_binders; | ||
970 | TyBuilder::new(b, param_count) | ||
971 | } | ||
972 | |||
973 | pub fn build(self) -> T { | ||
974 | let (b, subst) = self.build_internal(); | ||
975 | b.subst(&subst) | ||
976 | } | ||
977 | } | ||
978 | |||
979 | impl TyBuilder<Binders<Ty>> { | ||
980 | pub fn def_ty(db: &dyn HirDatabase, def: TyDefId) -> TyBuilder<Binders<Ty>> { | ||
981 | TyBuilder::subst_binders(db.ty(def.into())) | ||
982 | } | ||
983 | |||
984 | pub fn impl_self_ty(db: &dyn HirDatabase, def: hir_def::ImplId) -> TyBuilder<Binders<Ty>> { | ||
985 | TyBuilder::subst_binders(db.impl_self_ty(def)) | ||
986 | } | ||
987 | } | ||
988 | |||
959 | impl Ty { | 989 | impl Ty { |
960 | pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { | 990 | pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { |
961 | match self.kind(&Interner) { | 991 | match self.kind(&Interner) { |