aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r--crates/ra_hir_ty/src/lib.rs10
-rw-r--r--crates/ra_hir_ty/src/lower.rs4
2 files changed, 10 insertions, 4 deletions
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs
index a685e70c2..314be17b8 100644
--- a/crates/ra_hir_ty/src/lib.rs
+++ b/crates/ra_hir_ty/src/lib.rs
@@ -361,10 +361,16 @@ impl Substs {
361 } 361 }
362 362
363 /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). 363 /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`).
364 pub(crate) fn type_params(generic_params: &Generics) -> Substs { 364 pub(crate) fn type_params_for_generics(generic_params: &Generics) -> Substs {
365 Substs(generic_params.iter().map(|(id, _)| Ty::Param(id)).collect()) 365 Substs(generic_params.iter().map(|(id, _)| Ty::Param(id)).collect())
366 } 366 }
367 367
368 /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`).
369 pub fn type_params(db: &impl HirDatabase, def: impl Into<GenericDefId>) -> Substs {
370 let params = generics(db, def.into());
371 Substs::type_params_for_generics(&params)
372 }
373
368 /// Return Substs that replace each parameter by a bound variable. 374 /// Return Substs that replace each parameter by a bound variable.
369 pub(crate) fn bound_vars(generic_params: &Generics) -> Substs { 375 pub(crate) fn bound_vars(generic_params: &Generics) -> Substs {
370 Substs(generic_params.iter().enumerate().map(|(idx, _)| Ty::Bound(idx as u32)).collect()) 376 Substs(generic_params.iter().enumerate().map(|(idx, _)| Ty::Bound(idx as u32)).collect())
@@ -1026,7 +1032,7 @@ impl HirDisplay for Ty {
1026 TypeParamProvenance::ArgumentImplTrait => { 1032 TypeParamProvenance::ArgumentImplTrait => {
1027 write!(f, "impl ")?; 1033 write!(f, "impl ")?;
1028 let bounds = f.db.generic_predicates_for_param(*id); 1034 let bounds = f.db.generic_predicates_for_param(*id);
1029 let substs = Substs::type_params(&generics); 1035 let substs = Substs::type_params_for_generics(&generics);
1030 write_bounds_like_dyn_trait(&bounds.iter().map(|b| b.clone().subst(&substs)).collect::<Vec<_>>(), f)?; 1036 write_bounds_like_dyn_trait(&bounds.iter().map(|b| b.clone().subst(&substs)).collect::<Vec<_>>(), f)?;
1031 } 1037 }
1032 } 1038 }
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs
index 847111748..0d4c075af 100644
--- a/crates/ra_hir_ty/src/lower.rs
+++ b/crates/ra_hir_ty/src/lower.rs
@@ -276,7 +276,7 @@ impl Ty {
276 TypeNs::SelfType(impl_id) => { 276 TypeNs::SelfType(impl_id) => {
277 let generics = generics(ctx.db, impl_id.into()); 277 let generics = generics(ctx.db, impl_id.into());
278 let substs = match ctx.type_param_mode { 278 let substs = match ctx.type_param_mode {
279 TypeParamLoweringMode::Placeholder => Substs::type_params(&generics), 279 TypeParamLoweringMode::Placeholder => Substs::type_params_for_generics(&generics),
280 TypeParamLoweringMode::Variable => Substs::bound_vars(&generics), 280 TypeParamLoweringMode::Variable => Substs::bound_vars(&generics),
281 }; 281 };
282 ctx.db.impl_self_ty(impl_id).subst(&substs) 282 ctx.db.impl_self_ty(impl_id).subst(&substs)
@@ -284,7 +284,7 @@ impl Ty {
284 TypeNs::AdtSelfType(adt) => { 284 TypeNs::AdtSelfType(adt) => {
285 let generics = generics(ctx.db, adt.into()); 285 let generics = generics(ctx.db, adt.into());
286 let substs = match ctx.type_param_mode { 286 let substs = match ctx.type_param_mode {
287 TypeParamLoweringMode::Placeholder => Substs::type_params(&generics), 287 TypeParamLoweringMode::Placeholder => Substs::type_params_for_generics(&generics),
288 TypeParamLoweringMode::Variable => Substs::bound_vars(&generics), 288 TypeParamLoweringMode::Variable => Substs::bound_vars(&generics),
289 }; 289 };
290 ctx.db.ty(adt.into()).subst(&substs) 290 ctx.db.ty(adt.into()).subst(&substs)