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/attr.rs2
-rw-r--r--crates/ra_hir_def/src/child_by_source.rs4
-rw-r--r--crates/ra_hir_def/src/data.rs6
-rw-r--r--crates/ra_hir_def/src/db.rs6
-rw-r--r--crates/ra_hir_def/src/docs.rs2
-rw-r--r--crates/ra_hir_def/src/generics.rs2
-rw-r--r--crates/ra_hir_def/src/keys.rs4
-rw-r--r--crates/ra_hir_def/src/lib.rs30
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs9
-rw-r--r--crates/ra_hir_def/src/resolver.rs8
-rw-r--r--crates/ra_hir_def/src/src.rs11
11 files changed, 58 insertions, 26 deletions
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index 12d4e777a..3347d819c 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -60,7 +60,7 @@ impl Attrs {
60 AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), 60 AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
61 AdtId::UnionId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), 61 AdtId::UnionId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
62 }, 62 },
63 AttrDefId::TraitId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), 63 AttrDefId::TraitId(it) => attrs_from_loc(it.lookup(db), db),
64 AttrDefId::MacroDefId(it) => { 64 AttrDefId::MacroDefId(it) => {
65 it.ast_id.map_or_else(Default::default, |ast_id| attrs_from_ast(ast_id, db)) 65 it.ast_id.map_or_else(Default::default, |ast_id| attrs_from_ast(ast_id, db))
66 } 66 }
diff --git a/crates/ra_hir_def/src/child_by_source.rs b/crates/ra_hir_def/src/child_by_source.rs
index 821549bd5..88c2d3f24 100644
--- a/crates/ra_hir_def/src/child_by_source.rs
+++ b/crates/ra_hir_def/src/child_by_source.rs
@@ -94,6 +94,10 @@ impl ChildBySource for ModuleId {
94 let src = ty.lookup(db).source(db); 94 let src = ty.lookup(db).source(db);
95 res[keys::TYPE_ALIAS].insert(src, ty) 95 res[keys::TYPE_ALIAS].insert(src, ty)
96 } 96 }
97 ModuleDefId::TraitId(trait_) => {
98 let src = trait_.lookup(db).source(db);
99 res[keys::TRAIT].insert(src, trait_)
100 }
97 _ => (), 101 _ => (),
98 } 102 }
99 } 103 }
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index 42821b9b1..b2dac183e 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -12,8 +12,8 @@ use crate::{
12 db::DefDatabase, 12 db::DefDatabase,
13 src::HasSource, 13 src::HasSource,
14 type_ref::{Mutability, TypeRef}, 14 type_ref::{Mutability, TypeRef},
15 AssocItemId, AstItemDef, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, ImplId, 15 AssocItemId, ConstId, ConstLoc, ContainerId, FunctionId, FunctionLoc, ImplId, Intern, Lookup,
16 Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc, 16 StaticId, TraitId, TypeAliasId, TypeAliasLoc,
17}; 17};
18 18
19#[derive(Debug, Clone, PartialEq, Eq)] 19#[derive(Debug, Clone, PartialEq, Eq)]
@@ -94,7 +94,7 @@ pub struct TraitData {
94 94
95impl TraitData { 95impl TraitData {
96 pub(crate) fn trait_data_query(db: &impl DefDatabase, tr: TraitId) -> Arc<TraitData> { 96 pub(crate) fn trait_data_query(db: &impl DefDatabase, tr: TraitId) -> Arc<TraitData> {
97 let src = tr.source(db); 97 let src = tr.lookup(db).source(db);
98 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); 98 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
99 let auto = src.value.is_auto(); 99 let auto = src.value.is_auto();
100 let ast_id_map = db.ast_id_map(src.file_id); 100 let ast_id_map = db.ast_id_map(src.file_id);
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index 8907aacca..f0c2ae559 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -18,8 +18,8 @@ use crate::{
18 CrateDefMap, 18 CrateDefMap,
19 }, 19 },
20 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, FunctionId, FunctionLoc, GenericDefId, 20 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, FunctionId, FunctionLoc, GenericDefId,
21 ImplId, ImplLoc, ItemLoc, ModuleId, StaticId, StaticLoc, StructId, TraitId, TypeAliasId, 21 ImplId, ImplLoc, ItemLoc, ModuleId, StaticId, StaticLoc, StructId, TraitId, TraitLoc,
22 TypeAliasLoc, UnionId, 22 TypeAliasId, TypeAliasLoc, UnionId,
23}; 23};
24 24
25#[salsa::query_group(InternDatabaseStorage)] 25#[salsa::query_group(InternDatabaseStorage)]
@@ -37,7 +37,7 @@ pub trait InternDatabase: SourceDatabase {
37 #[salsa::interned] 37 #[salsa::interned]
38 fn intern_static(&self, loc: StaticLoc) -> StaticId; 38 fn intern_static(&self, loc: StaticLoc) -> StaticId;
39 #[salsa::interned] 39 #[salsa::interned]
40 fn intern_trait(&self, loc: ItemLoc<ast::TraitDef>) -> TraitId; 40 fn intern_trait(&self, loc: TraitLoc) -> TraitId;
41 #[salsa::interned] 41 #[salsa::interned]
42 fn intern_type_alias(&self, loc: TypeAliasLoc) -> TypeAliasId; 42 fn intern_type_alias(&self, loc: TypeAliasLoc) -> TypeAliasId;
43 #[salsa::interned] 43 #[salsa::interned]
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs
index 61727bd26..1921681fb 100644
--- a/crates/ra_hir_def/src/docs.rs
+++ b/crates/ra_hir_def/src/docs.rs
@@ -59,7 +59,7 @@ impl Documentation {
59 let src = it.parent.child_source(db); 59 let src = it.parent.child_source(db);
60 docs_from_ast(&src.value[it.local_id]) 60 docs_from_ast(&src.value[it.local_id])
61 } 61 }
62 AttrDefId::TraitId(it) => docs_from_ast(&it.source(db).value), 62 AttrDefId::TraitId(it) => docs_from_ast(&it.lookup(db).source(db).value),
63 AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id?.to_node(db)), 63 AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id?.to_node(db)),
64 AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value), 64 AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value),
65 AttrDefId::StaticId(it) => docs_from_ast(&it.lookup(db).source(db).value), 65 AttrDefId::StaticId(it) => docs_from_ast(&it.lookup(db).source(db).value),
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index 5d1100945..cbfc3ff04 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -86,7 +86,7 @@ impl GenericParams {
86 src.file_id 86 src.file_id
87 } 87 }
88 GenericDefId::TraitId(it) => { 88 GenericDefId::TraitId(it) => {
89 let src = it.source(db); 89 let src = it.lookup(db).source(db);
90 90
91 // traits get the Self type as an implicit first type parameter 91 // traits get the Self type as an implicit first type parameter
92 let self_param_id = 92 let self_param_id =
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs
index d318b2451..6ec58f5f9 100644
--- a/crates/ra_hir_def/src/keys.rs
+++ b/crates/ra_hir_def/src/keys.rs
@@ -8,7 +8,8 @@ use rustc_hash::FxHashMap;
8 8
9use crate::{ 9use crate::{
10 dyn_map::{DynMap, Policy}, 10 dyn_map::{DynMap, Policy},
11 ConstId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, TypeAliasId, TypeParamId, 11 ConstId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, TraitId, TypeAliasId,
12 TypeParamId,
12}; 13};
13 14
14type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>; 15type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>;
@@ -18,6 +19,7 @@ pub const CONST: Key<ast::ConstDef, ConstId> = Key::new();
18pub const STATIC: Key<ast::StaticDef, StaticId> = Key::new(); 19pub const STATIC: Key<ast::StaticDef, StaticId> = Key::new();
19pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new(); 20pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new();
20pub const IMPL: Key<ast::ImplBlock, ImplId> = Key::new(); 21pub const IMPL: Key<ast::ImplBlock, ImplId> = Key::new();
22pub const TRAIT: Key<ast::TraitDef, TraitId> = Key::new();
21 23
22pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new(); 24pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new();
23pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); 25pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new();
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 5564b166b..0fcc2cde4 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -253,12 +253,24 @@ impl Lookup for StaticId {
253#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 253#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
254pub struct TraitId(salsa::InternId); 254pub struct TraitId(salsa::InternId);
255impl_intern_key!(TraitId); 255impl_intern_key!(TraitId);
256impl AstItemDef<ast::TraitDef> for TraitId { 256
257 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::TraitDef>) -> Self { 257#[derive(Debug, Clone, PartialEq, Eq, Hash)]
258 db.intern_trait(loc) 258pub struct TraitLoc {
259 pub container: ModuleId,
260 pub ast_id: AstId<ast::TraitDef>,
261}
262
263impl Intern for TraitLoc {
264 type ID = TraitId;
265 fn intern(self, db: &impl db::DefDatabase) -> TraitId {
266 db.intern_trait(self)
259 } 267 }
260 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::TraitDef> { 268}
261 db.lookup_intern_trait(self) 269
270impl Lookup for TraitId {
271 type Data = TraitLoc;
272 fn lookup(&self, db: &impl db::DefDatabase) -> TraitLoc {
273 db.lookup_intern_trait(*self)
262 } 274 }
263} 275}
264 276
@@ -492,7 +504,7 @@ impl HasModule for FunctionLoc {
492 match self.container { 504 match self.container {
493 ContainerId::ModuleId(it) => it, 505 ContainerId::ModuleId(it) => it,
494 ContainerId::ImplId(it) => it.lookup(db).container, 506 ContainerId::ImplId(it) => it.lookup(db).container,
495 ContainerId::TraitId(it) => it.module(db), 507 ContainerId::TraitId(it) => it.lookup(db).container,
496 } 508 }
497 } 509 }
498} 510}
@@ -502,7 +514,7 @@ impl HasModule for TypeAliasLoc {
502 match self.container { 514 match self.container {
503 ContainerId::ModuleId(it) => it, 515 ContainerId::ModuleId(it) => it,
504 ContainerId::ImplId(it) => it.lookup(db).container, 516 ContainerId::ImplId(it) => it.lookup(db).container,
505 ContainerId::TraitId(it) => it.module(db), 517 ContainerId::TraitId(it) => it.lookup(db).container,
506 } 518 }
507 } 519 }
508} 520}
@@ -512,7 +524,7 @@ impl HasModule for ConstLoc {
512 match self.container { 524 match self.container {
513 ContainerId::ModuleId(it) => it, 525 ContainerId::ModuleId(it) => it,
514 ContainerId::ImplId(it) => it.lookup(db).container, 526 ContainerId::ImplId(it) => it.lookup(db).container,
515 ContainerId::TraitId(it) => it.module(db), 527 ContainerId::TraitId(it) => it.lookup(db).container,
516 } 528 }
517 } 529 }
518} 530}
@@ -542,7 +554,7 @@ impl HasModule for GenericDefId {
542 match self { 554 match self {
543 GenericDefId::FunctionId(it) => it.lookup(db).module(db), 555 GenericDefId::FunctionId(it) => it.lookup(db).module(db),
544 GenericDefId::AdtId(it) => it.module(db), 556 GenericDefId::AdtId(it) => it.module(db),
545 GenericDefId::TraitId(it) => it.module(db), 557 GenericDefId::TraitId(it) => it.lookup(db).container,
546 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), 558 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
547 GenericDefId::ImplId(it) => it.lookup(db).container, 559 GenericDefId::ImplId(it) => it.lookup(db).container,
548 GenericDefId::EnumVariantId(it) => it.parent.module(db), 560 GenericDefId::EnumVariantId(it) => it.parent.module(db),
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index b33507a9a..a7bdd620b 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -26,7 +26,7 @@ use crate::{
26 per_ns::PerNs, 26 per_ns::PerNs,
27 AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplLoc, 27 AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplLoc,
28 Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId, 28 Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId,
29 TraitId, TypeAliasLoc, UnionId, 29 TraitLoc, TypeAliasLoc, UnionId,
30}; 30};
31 31
32pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { 32pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
@@ -796,7 +796,12 @@ where
796 796
797 PerNs::values(def.into()) 797 PerNs::values(def.into())
798 } 798 }
799 raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()), 799 raw::DefKind::Trait(ast_id) => {
800 let def = TraitLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) }
801 .intern(self.def_collector.db);
802
803 PerNs::types(def.into())
804 }
800 raw::DefKind::TypeAlias(ast_id) => { 805 raw::DefKind::TypeAlias(ast_id) => {
801 let def = TypeAliasLoc { 806 let def = TypeAliasLoc {
802 container: ContainerId::ModuleId(module), 807 container: ContainerId::ModuleId(module),
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index f87b16b44..17b2169d2 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -17,9 +17,9 @@ use crate::{
17 nameres::{BuiltinShadowMode, CrateDefMap}, 17 nameres::{BuiltinShadowMode, CrateDefMap},
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, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, GenericDefId,
21 GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, 21 HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId,
22 StructId, TraitId, TypeAliasId, TypeParamId, VariantId, 22 TypeAliasId, TypeParamId, VariantId,
23}; 23};
24 24
25#[derive(Debug, Clone, Default)] 25#[derive(Debug, Clone, Default)]
@@ -524,7 +524,7 @@ impl HasResolver for ModuleId {
524 524
525impl HasResolver for TraitId { 525impl HasResolver for TraitId {
526 fn resolver(self, db: &impl DefDatabase) -> Resolver { 526 fn resolver(self, db: &impl DefDatabase) -> Resolver {
527 self.module(db).resolver(db).push_generic_params_scope(db, self.into()) 527 self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
528 } 528 }
529} 529}
530 530
diff --git a/crates/ra_hir_def/src/src.rs b/crates/ra_hir_def/src/src.rs
index a5c4359a7..858e4861e 100644
--- a/crates/ra_hir_def/src/src.rs
+++ b/crates/ra_hir_def/src/src.rs
@@ -4,7 +4,7 @@ use hir_expand::InFile;
4use ra_arena::map::ArenaMap; 4use ra_arena::map::ArenaMap;
5use ra_syntax::ast; 5use ra_syntax::ast;
6 6
7use crate::{db::DefDatabase, ConstLoc, FunctionLoc, ImplLoc, StaticLoc, TypeAliasLoc}; 7use crate::{db::DefDatabase, ConstLoc, FunctionLoc, ImplLoc, StaticLoc, TraitLoc, TypeAliasLoc};
8 8
9pub trait HasSource { 9pub trait HasSource {
10 type Value; 10 type Value;
@@ -56,6 +56,15 @@ impl HasSource for ImplLoc {
56 } 56 }
57} 57}
58 58
59impl HasSource for TraitLoc {
60 type Value = ast::TraitDef;
61
62 fn source(&self, db: &impl DefDatabase) -> InFile<ast::TraitDef> {
63 let node = self.ast_id.to_node(db);
64 InFile::new(self.ast_id.file_id, node)
65 }
66}
67
59pub trait HasChildSource { 68pub trait HasChildSource {
60 type ChildId; 69 type ChildId;
61 type Value; 70 type Value;