diff options
author | Aleksey Kladov <[email protected]> | 2019-12-07 19:09:53 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-12-07 19:25:48 +0000 |
commit | 88c5b1282a5770097c6c768b24bedfc3a6944e08 (patch) | |
tree | 913c24e889f3db8044b4b9f11bc3969e7eb02e34 /crates/ra_hir_def/src/generics.rs | |
parent | f4f8b8147426b0096d4b5126e487caaa13d13c27 (diff) |
Rename GenericParam -> TypeParam
We don't have LifetimeParam yet, but they are planned!
Diffstat (limited to 'crates/ra_hir_def/src/generics.rs')
-rw-r--r-- | crates/ra_hir_def/src/generics.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index 159f9034b..976cf72d0 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs | |||
@@ -21,12 +21,12 @@ use crate::{ | |||
21 | src::HasChildSource, | 21 | src::HasChildSource, |
22 | src::HasSource, | 22 | src::HasSource, |
23 | type_ref::{TypeBound, TypeRef}, | 23 | type_ref::{TypeBound, TypeRef}, |
24 | AdtId, AstItemDef, GenericDefId, GenericParamId, LocalGenericParamId, Lookup, | 24 | AdtId, AstItemDef, GenericDefId, LocalTypeParamId, Lookup, TypeParamId, |
25 | }; | 25 | }; |
26 | 26 | ||
27 | /// Data about a generic parameter (to a function, struct, impl, ...). | 27 | /// Data about a generic parameter (to a function, struct, impl, ...). |
28 | #[derive(Clone, PartialEq, Eq, Debug)] | 28 | #[derive(Clone, PartialEq, Eq, Debug)] |
29 | pub struct GenericParamData { | 29 | pub struct TypeParamData { |
30 | pub name: Name, | 30 | pub name: Name, |
31 | pub default: Option<TypeRef>, | 31 | pub default: Option<TypeRef>, |
32 | } | 32 | } |
@@ -34,7 +34,8 @@ pub struct GenericParamData { | |||
34 | /// Data about the generic parameters of a function, struct, impl, etc. | 34 | /// Data about the generic parameters of a function, struct, impl, etc. |
35 | #[derive(Clone, PartialEq, Eq, Debug)] | 35 | #[derive(Clone, PartialEq, Eq, Debug)] |
36 | pub struct GenericParams { | 36 | pub struct GenericParams { |
37 | pub params: Arena<LocalGenericParamId, GenericParamData>, | 37 | pub types: Arena<LocalTypeParamId, TypeParamData>, |
38 | // lifetimes: Arena<LocalLifetimeParamId, LifetimeParamData>, | ||
38 | pub where_predicates: Vec<WherePredicate>, | 39 | pub where_predicates: Vec<WherePredicate>, |
39 | } | 40 | } |
40 | 41 | ||
@@ -48,7 +49,7 @@ pub struct WherePredicate { | |||
48 | pub bound: TypeBound, | 49 | pub bound: TypeBound, |
49 | } | 50 | } |
50 | 51 | ||
51 | type SourceMap = ArenaMap<LocalGenericParamId, Either<ast::TraitDef, ast::TypeParam>>; | 52 | type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::TraitDef, ast::TypeParam>>; |
52 | 53 | ||
53 | impl GenericParams { | 54 | impl GenericParams { |
54 | pub(crate) fn generic_params_query( | 55 | pub(crate) fn generic_params_query( |
@@ -60,7 +61,7 @@ impl GenericParams { | |||
60 | } | 61 | } |
61 | 62 | ||
62 | fn new(db: &impl DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) { | 63 | fn new(db: &impl DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) { |
63 | let mut generics = GenericParams { params: Arena::default(), where_predicates: Vec::new() }; | 64 | let mut generics = GenericParams { types: Arena::default(), where_predicates: Vec::new() }; |
64 | let mut sm = ArenaMap::default(); | 65 | let mut sm = ArenaMap::default(); |
65 | // FIXME: add `: Sized` bound for everything except for `Self` in traits | 66 | // FIXME: add `: Sized` bound for everything except for `Self` in traits |
66 | let file_id = match def { | 67 | let file_id = match def { |
@@ -88,9 +89,8 @@ impl GenericParams { | |||
88 | let src = it.source(db); | 89 | let src = it.source(db); |
89 | 90 | ||
90 | // traits get the Self type as an implicit first type parameter | 91 | // traits get the Self type as an implicit first type parameter |
91 | let self_param_id = generics | 92 | let self_param_id = |
92 | .params | 93 | generics.types.alloc(TypeParamData { name: name::SELF_TYPE, default: None }); |
93 | .alloc(GenericParamData { name: name::SELF_TYPE, default: None }); | ||
94 | sm.insert(self_param_id, Either::Left(src.value.clone())); | 94 | sm.insert(self_param_id, Either::Left(src.value.clone())); |
95 | // add super traits as bounds on Self | 95 | // add super traits as bounds on Self |
96 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar | 96 | // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar |
@@ -142,8 +142,8 @@ impl GenericParams { | |||
142 | let name = type_param.name().map_or_else(Name::missing, |it| it.as_name()); | 142 | let name = type_param.name().map_or_else(Name::missing, |it| it.as_name()); |
143 | // FIXME: Use `Path::from_src` | 143 | // FIXME: Use `Path::from_src` |
144 | let default = type_param.default_type().map(TypeRef::from_ast); | 144 | let default = type_param.default_type().map(TypeRef::from_ast); |
145 | let param = GenericParamData { name: name.clone(), default }; | 145 | let param = TypeParamData { name: name.clone(), default }; |
146 | let param_id = self.params.alloc(param); | 146 | let param_id = self.types.alloc(param); |
147 | sm.insert(param_id, Either::Right(type_param.clone())); | 147 | sm.insert(param_id, Either::Right(type_param.clone())); |
148 | 148 | ||
149 | let type_ref = TypeRef::Path(name.into()); | 149 | let type_ref = TypeRef::Path(name.into()); |
@@ -173,13 +173,13 @@ impl GenericParams { | |||
173 | self.where_predicates.push(WherePredicate { type_ref, bound }); | 173 | self.where_predicates.push(WherePredicate { type_ref, bound }); |
174 | } | 174 | } |
175 | 175 | ||
176 | pub fn find_by_name(&self, name: &Name) -> Option<LocalGenericParamId> { | 176 | pub fn find_by_name(&self, name: &Name) -> Option<LocalTypeParamId> { |
177 | self.params.iter().find_map(|(id, p)| if &p.name == name { Some(id) } else { None }) | 177 | self.types.iter().find_map(|(id, p)| if &p.name == name { Some(id) } else { None }) |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | impl HasChildSource for GenericDefId { | 181 | impl HasChildSource for GenericDefId { |
182 | type ChildId = LocalGenericParamId; | 182 | type ChildId = LocalTypeParamId; |
183 | type Value = Either<ast::TraitDef, ast::TypeParam>; | 183 | type Value = Either<ast::TraitDef, ast::TypeParam>; |
184 | fn child_source(&self, db: &impl DefDatabase) -> InFile<SourceMap> { | 184 | fn child_source(&self, db: &impl DefDatabase) -> InFile<SourceMap> { |
185 | let (_, sm) = GenericParams::new(db, *self); | 185 | let (_, sm) = GenericParams::new(db, *self); |
@@ -193,7 +193,7 @@ impl ChildBySource for GenericDefId { | |||
193 | let arena_map = self.child_source(db); | 193 | let arena_map = self.child_source(db); |
194 | let arena_map = arena_map.as_ref(); | 194 | let arena_map = arena_map.as_ref(); |
195 | for (local_id, src) in arena_map.value.iter() { | 195 | for (local_id, src) in arena_map.value.iter() { |
196 | let id = GenericParamId { parent: *self, local_id }; | 196 | let id = TypeParamId { parent: *self, local_id }; |
197 | if let Either::Right(type_param) = src { | 197 | if let Either::Right(type_param) = src { |
198 | res[keys::TYPE_PARAM].insert(arena_map.with_value(type_param.clone()), id) | 198 | res[keys::TYPE_PARAM].insert(arena_map.with_value(type_param.clone()), id) |
199 | } | 199 | } |