aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-04 12:16:16 +0100
committerFlorian Diebold <[email protected]>2021-04-04 12:16:39 +0100
commitebdfc932e74ff11c8c14c513614212b7c07bf400 (patch)
tree85263e70c101206330ed95c00ce226a61c098c0c
parenta4d7bdf1c884a9f3dd415a882fa56422adae89bf (diff)
Replace Substitution::type_params
-rw-r--r--crates/hir/src/display.rs4
-rw-r--r--crates/hir/src/lib.rs4
-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
6 files changed, 15 insertions, 16 deletions
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs
index 559ea31a0..993772aac 100644
--- a/crates/hir/src/display.rs
+++ b/crates/hir/src/display.rs
@@ -13,7 +13,7 @@ use syntax::ast::{self, NameOwner};
13 13
14use crate::{ 14use crate::{
15 Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasVisibility, LifetimeParam, 15 Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasVisibility, LifetimeParam,
16 Module, Static, Struct, Substitution, Trait, Type, TypeAlias, TypeParam, Union, Variant, 16 Module, Static, Struct, Trait, TyBuilder, Type, TypeAlias, TypeParam, Union, Variant,
17}; 17};
18 18
19impl HirDisplay for Function { 19impl HirDisplay for Function {
@@ -234,7 +234,7 @@ impl HirDisplay for TypeParam {
234 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { 234 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
235 write!(f, "{}", self.name(f.db))?; 235 write!(f, "{}", self.name(f.db))?;
236 let bounds = f.db.generic_predicates_for_param(self.id); 236 let bounds = f.db.generic_predicates_for_param(self.id);
237 let substs = Substitution::type_params(f.db, self.id.parent); 237 let substs = TyBuilder::type_params_subst(f.db, self.id.parent);
238 let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>(); 238 let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>();
239 if !(predicates.is_empty() || f.omit_verbose_types()) { 239 if !(predicates.is_empty() || f.omit_verbose_types()) {
240 write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?; 240 write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?;
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 42ae53c66..19901ed33 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -514,7 +514,7 @@ impl Field {
514 VariantDef::Union(it) => it.id.into(), 514 VariantDef::Union(it) => it.id.into(),
515 VariantDef::Variant(it) => it.parent.id.into(), 515 VariantDef::Variant(it) => it.parent.id.into(),
516 }; 516 };
517 let substs = Substitution::type_params(db, generic_def_id); 517 let substs = TyBuilder::type_params_subst(db, generic_def_id);
518 let ty = db.field_types(var_id)[self.id].clone().subst(&substs); 518 let ty = db.field_types(var_id)[self.id].clone().subst(&substs);
519 Type::new(db, self.parent.module(db).id.krate(), var_id, ty) 519 Type::new(db, self.parent.module(db).id.krate(), var_id, ty)
520 } 520 }
@@ -1501,7 +1501,7 @@ impl TypeParam {
1501 let resolver = self.id.parent.resolver(db.upcast()); 1501 let resolver = self.id.parent.resolver(db.upcast());
1502 let krate = self.id.parent.module(db.upcast()).krate(); 1502 let krate = self.id.parent.module(db.upcast()).krate();
1503 let ty = params.get(local_idx)?.clone(); 1503 let ty = params.get(local_idx)?.clone();
1504 let subst = Substitution::type_params(db, self.id.parent); 1504 let subst = TyBuilder::type_params_subst(db, self.id.parent);
1505 let ty = ty.subst(&subst.prefix(local_idx)); 1505 let ty = ty.subst(&subst.prefix(local_idx));
1506 Some(Type::new_with_resolver_inner(db, krate, &resolver, ty)) 1506 Some(Type::new_with_resolver_inner(db, krate, &resolver, ty))
1507 } 1507 }
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);