aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/generics.rs20
-rw-r--r--crates/ra_hir_def/src/keys.rs3
-rw-r--r--crates/ra_hir_def/src/lib.rs14
3 files changed, 35 insertions, 2 deletions
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index 0df5a20f5..159f9034b 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -14,11 +14,14 @@ use ra_db::FileId;
14use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner}; 14use ra_syntax::ast::{self, NameOwner, TypeBoundsOwner, TypeParamsOwner};
15 15
16use crate::{ 16use crate::{
17 child_by_source::ChildBySource,
17 db::DefDatabase, 18 db::DefDatabase,
19 dyn_map::DynMap,
20 keys,
18 src::HasChildSource, 21 src::HasChildSource,
19 src::HasSource, 22 src::HasSource,
20 type_ref::{TypeBound, TypeRef}, 23 type_ref::{TypeBound, TypeRef},
21 AdtId, AstItemDef, GenericDefId, LocalGenericParamId, Lookup, 24 AdtId, AstItemDef, GenericDefId, GenericParamId, LocalGenericParamId, Lookup,
22}; 25};
23 26
24/// Data about a generic parameter (to a function, struct, impl, ...). 27/// Data about a generic parameter (to a function, struct, impl, ...).
@@ -183,3 +186,18 @@ impl HasChildSource for GenericDefId {
183 sm 186 sm
184 } 187 }
185} 188}
189
190impl ChildBySource for GenericDefId {
191 fn child_by_source(&self, db: &impl DefDatabase) -> DynMap {
192 let mut res = DynMap::default();
193 let arena_map = self.child_source(db);
194 let arena_map = arena_map.as_ref();
195 for (local_id, src) in arena_map.value.iter() {
196 let id = GenericParamId { parent: *self, local_id };
197 if let Either::Right(type_param) = src {
198 res[keys::TYPE_PARAM].insert(arena_map.with_value(type_param.clone()), id)
199 }
200 }
201 res
202 }
203}
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs
index 447b7e3ba..ca5630c80 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
9use crate::{ 9use crate::{
10 dyn_map::{DynMap, Policy}, 10 dyn_map::{DynMap, Policy},
11 ConstId, EnumVariantId, FunctionId, StaticId, StructFieldId, TypeAliasId, 11 ConstId, EnumVariantId, FunctionId, GenericParamId, StaticId, StructFieldId, TypeAliasId,
12}; 12};
13 13
14type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; 14type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>;
@@ -20,6 +20,7 @@ pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new();
20pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new(); 20pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new();
21pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); 21pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new();
22pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new(); 22pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new();
23pub const TYPE_PARAM: Key<ast::TypeParam, GenericParamId> = Key::new();
23 24
24/// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are 25/// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are
25/// 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 b8dfc0ab1..6dfb3c03d 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -525,6 +525,20 @@ impl HasModule for DefWithBodyId {
525 } 525 }
526} 526}
527 527
528impl HasModule for GenericDefId {
529 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
530 match self {
531 GenericDefId::FunctionId(it) => it.lookup(db).module(db),
532 GenericDefId::AdtId(it) => it.module(db),
533 GenericDefId::TraitId(it) => it.module(db),
534 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
535 GenericDefId::ImplId(it) => it.module(db),
536 GenericDefId::EnumVariantId(it) => it.parent.module(db),
537 GenericDefId::ConstId(it) => it.lookup(db).module(db),
538 }
539 }
540}
541
528impl HasModule for StaticLoc { 542impl HasModule for StaticLoc {
529 fn module(&self, _db: &impl db::DefDatabase) -> ModuleId { 543 fn module(&self, _db: &impl db::DefDatabase) -> ModuleId {
530 self.container 544 self.container