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/utils.rs26
1 files changed, 12 insertions, 14 deletions
diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs
index 936cfe25e..aeb211a91 100644
--- a/crates/ra_hir_ty/src/utils.rs
+++ b/crates/ra_hir_ty/src/utils.rs
@@ -5,10 +5,10 @@ use std::sync::Arc;
5use hir_def::{ 5use hir_def::{
6 adt::VariantData, 6 adt::VariantData,
7 db::DefDatabase, 7 db::DefDatabase,
8 generics::{GenericParamData, GenericParams}, 8 generics::{GenericParams, TypeParamData},
9 resolver::{HasResolver, TypeNs}, 9 resolver::{HasResolver, TypeNs},
10 type_ref::TypeRef, 10 type_ref::TypeRef,
11 ContainerId, GenericDefId, GenericParamId, Lookup, TraitId, TypeAliasId, VariantId, 11 ContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, TypeParamId, VariantId,
12}; 12};
13use hir_expand::name::{self, Name}; 13use hir_expand::name::{self, Name};
14 14
@@ -96,23 +96,21 @@ pub(crate) struct Generics {
96} 96}
97 97
98impl Generics { 98impl Generics {
99 pub(crate) fn iter<'a>(&'a self) -> impl Iterator<Item = (u32, &'a GenericParamData)> + 'a { 99 pub(crate) fn iter<'a>(&'a self) -> impl Iterator<Item = (u32, &'a TypeParamData)> + 'a {
100 self.parent_generics 100 self.parent_generics
101 .as_ref() 101 .as_ref()
102 .into_iter() 102 .into_iter()
103 .flat_map(|it| it.params.params.iter()) 103 .flat_map(|it| it.params.types.iter())
104 .chain(self.params.params.iter()) 104 .chain(self.params.types.iter())
105 .enumerate() 105 .enumerate()
106 .map(|(i, (_local_id, p))| (i as u32, p)) 106 .map(|(i, (_local_id, p))| (i as u32, p))
107 } 107 }
108 108
109 pub(crate) fn iter_parent<'a>( 109 pub(crate) fn iter_parent<'a>(&'a self) -> impl Iterator<Item = (u32, &'a TypeParamData)> + 'a {
110 &'a self,
111 ) -> impl Iterator<Item = (u32, &'a GenericParamData)> + 'a {
112 self.parent_generics 110 self.parent_generics
113 .as_ref() 111 .as_ref()
114 .into_iter() 112 .into_iter()
115 .flat_map(|it| it.params.params.iter()) 113 .flat_map(|it| it.params.types.iter())
116 .enumerate() 114 .enumerate()
117 .map(|(i, (_local_id, p))| (i as u32, p)) 115 .map(|(i, (_local_id, p))| (i as u32, p))
118 } 116 }
@@ -123,20 +121,20 @@ impl Generics {
123 /// (total, parents, child) 121 /// (total, parents, child)
124 pub(crate) fn len_split(&self) -> (usize, usize, usize) { 122 pub(crate) fn len_split(&self) -> (usize, usize, usize) {
125 let parent = self.parent_generics.as_ref().map_or(0, |p| p.len()); 123 let parent = self.parent_generics.as_ref().map_or(0, |p| p.len());
126 let child = self.params.params.len(); 124 let child = self.params.types.len();
127 (parent + child, parent, child) 125 (parent + child, parent, child)
128 } 126 }
129 pub(crate) fn param_idx(&self, param: GenericParamId) -> u32 { 127 pub(crate) fn param_idx(&self, param: TypeParamId) -> u32 {
130 self.find_param(param).0 128 self.find_param(param).0
131 } 129 }
132 pub(crate) fn param_name(&self, param: GenericParamId) -> Name { 130 pub(crate) fn param_name(&self, param: TypeParamId) -> Name {
133 self.find_param(param).1.name.clone() 131 self.find_param(param).1.name.clone()
134 } 132 }
135 fn find_param(&self, param: GenericParamId) -> (u32, &GenericParamData) { 133 fn find_param(&self, param: TypeParamId) -> (u32, &TypeParamData) {
136 if param.parent == self.def { 134 if param.parent == self.def {
137 let (idx, (_local_id, data)) = self 135 let (idx, (_local_id, data)) = self
138 .params 136 .params
139 .params 137 .types
140 .iter() 138 .iter()
141 .enumerate() 139 .enumerate()
142 .find(|(_, (idx, _))| *idx == param.local_id) 140 .find(|(_, (idx, _))| *idx == param.local_id)