diff options
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/generics.rs | 28 | ||||
-rw-r--r-- | crates/ra_hir_def/src/keys.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 18 |
4 files changed, 29 insertions, 29 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 | } |
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs index ca5630c80..be702a4f8 100644 --- a/crates/ra_hir_def/src/keys.rs +++ b/crates/ra_hir_def/src/keys.rs | |||
@@ -8,7 +8,7 @@ use rustc_hash::FxHashMap; | |||
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | dyn_map::{DynMap, Policy}, | 10 | dyn_map::{DynMap, Policy}, |
11 | ConstId, EnumVariantId, FunctionId, GenericParamId, StaticId, StructFieldId, TypeAliasId, | 11 | ConstId, EnumVariantId, FunctionId, StaticId, StructFieldId, TypeAliasId, TypeParamId, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; | 14 | type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; |
@@ -20,7 +20,7 @@ pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new(); | |||
20 | pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new(); | 20 | pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new(); |
21 | pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); | 21 | pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); |
22 | pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new(); | 22 | pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new(); |
23 | pub const TYPE_PARAM: Key<ast::TypeParam, GenericParamId> = Key::new(); | 23 | pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); |
24 | 24 | ||
25 | /// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are | 25 | /// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are |
26 | /// equal if they point to exactly the same object. | 26 | /// equal if they point to exactly the same object. |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 6dfb3c03d..569da4f28 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -318,14 +318,14 @@ macro_rules! impl_froms { | |||
318 | } | 318 | } |
319 | 319 | ||
320 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 320 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
321 | pub struct GenericParamId { | 321 | pub struct TypeParamId { |
322 | pub parent: GenericDefId, | 322 | pub parent: GenericDefId, |
323 | pub local_id: LocalGenericParamId, | 323 | pub local_id: LocalTypeParamId, |
324 | } | 324 | } |
325 | 325 | ||
326 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 326 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
327 | pub struct LocalGenericParamId(RawId); | 327 | pub struct LocalTypeParamId(RawId); |
328 | impl_arena_id!(LocalGenericParamId); | 328 | impl_arena_id!(LocalTypeParamId); |
329 | 329 | ||
330 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 330 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
331 | pub enum ContainerId { | 331 | pub enum ContainerId { |
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index e00bd03d5..4c859e497 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -18,8 +18,8 @@ use crate::{ | |||
18 | path::{Path, PathKind}, | 18 | path::{Path, PathKind}, |
19 | per_ns::PerNs, | 19 | per_ns::PerNs, |
20 | AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, | 20 | AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, |
21 | GenericDefId, GenericParamId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, | 21 | GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, |
22 | StaticId, StructId, TraitId, TypeAliasId, | 22 | StructId, TraitId, TypeAliasId, TypeParamId, |
23 | }; | 23 | }; |
24 | 24 | ||
25 | #[derive(Debug, Clone, Default)] | 25 | #[derive(Debug, Clone, Default)] |
@@ -59,7 +59,7 @@ enum Scope { | |||
59 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 59 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
60 | pub enum TypeNs { | 60 | pub enum TypeNs { |
61 | SelfType(ImplId), | 61 | SelfType(ImplId), |
62 | GenericParam(GenericParamId), | 62 | GenericParam(TypeParamId), |
63 | AdtId(AdtId), | 63 | AdtId(AdtId), |
64 | AdtSelfType(AdtId), | 64 | AdtSelfType(AdtId), |
65 | // Yup, enum variants are added to the types ns, but any usage of variant as | 65 | // Yup, enum variants are added to the types ns, but any usage of variant as |
@@ -157,7 +157,7 @@ impl Resolver { | |||
157 | if let Some(local_id) = params.find_by_name(first_name) { | 157 | if let Some(local_id) = params.find_by_name(first_name) { |
158 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; | 158 | let idx = if path.segments.len() == 1 { None } else { Some(1) }; |
159 | return Some(( | 159 | return Some(( |
160 | TypeNs::GenericParam(GenericParamId { local_id, parent: *def }), | 160 | TypeNs::GenericParam(TypeParamId { local_id, parent: *def }), |
161 | idx, | 161 | idx, |
162 | )); | 162 | )); |
163 | } | 163 | } |
@@ -252,7 +252,7 @@ impl Resolver { | |||
252 | 252 | ||
253 | Scope::GenericParams { params, def } if n_segments > 1 => { | 253 | Scope::GenericParams { params, def } if n_segments > 1 => { |
254 | if let Some(local_id) = params.find_by_name(first_name) { | 254 | if let Some(local_id) = params.find_by_name(first_name) { |
255 | let ty = TypeNs::GenericParam(GenericParamId { local_id, parent: *def }); | 255 | let ty = TypeNs::GenericParam(TypeParamId { local_id, parent: *def }); |
256 | return Some(ResolveValueResult::Partial(ty, 1)); | 256 | return Some(ResolveValueResult::Partial(ty, 1)); |
257 | } | 257 | } |
258 | } | 258 | } |
@@ -399,7 +399,7 @@ pub enum ScopeDef { | |||
399 | PerNs(PerNs), | 399 | PerNs(PerNs), |
400 | ImplSelfType(ImplId), | 400 | ImplSelfType(ImplId), |
401 | AdtSelfType(AdtId), | 401 | AdtSelfType(AdtId), |
402 | GenericParam(GenericParamId), | 402 | GenericParam(TypeParamId), |
403 | Local(PatId), | 403 | Local(PatId), |
404 | } | 404 | } |
405 | 405 | ||
@@ -431,10 +431,10 @@ impl Scope { | |||
431 | } | 431 | } |
432 | } | 432 | } |
433 | Scope::GenericParams { params, def } => { | 433 | Scope::GenericParams { params, def } => { |
434 | for (local_id, param) in params.params.iter() { | 434 | for (local_id, param) in params.types.iter() { |
435 | f( | 435 | f( |
436 | param.name.clone(), | 436 | param.name.clone(), |
437 | ScopeDef::GenericParam(GenericParamId { local_id, parent: *def }), | 437 | ScopeDef::GenericParam(TypeParamId { local_id, parent: *def }), |
438 | ) | 438 | ) |
439 | } | 439 | } |
440 | } | 440 | } |
@@ -481,7 +481,7 @@ impl Resolver { | |||
481 | 481 | ||
482 | fn push_generic_params_scope(self, db: &impl DefDatabase, def: GenericDefId) -> Resolver { | 482 | fn push_generic_params_scope(self, db: &impl DefDatabase, def: GenericDefId) -> Resolver { |
483 | let params = db.generic_params(def); | 483 | let params = db.generic_params(def); |
484 | if params.params.is_empty() { | 484 | if params.types.is_empty() { |
485 | self | 485 | self |
486 | } else { | 486 | } else { |
487 | self.push_scope(Scope::GenericParams { def, params }) | 487 | self.push_scope(Scope::GenericParams { def, params }) |