diff options
Diffstat (limited to 'crates/ra_hir_ty/src/lib.rs')
-rw-r--r-- | crates/ra_hir_ty/src/lib.rs | 10 |
1 files changed, 8 insertions, 2 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(¶ms) | ||
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 | } |