diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/db.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_def/src/docs.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 37 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 2 |
8 files changed, 46 insertions, 14 deletions
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index 48ce8cd93..87f411599 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -63,11 +63,11 @@ impl Attrs { | |||
63 | AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | 63 | AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), |
64 | AdtId::UnionId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db), | 64 | AdtId::UnionId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db), |
65 | }, | 65 | }, |
66 | AttrDefId::StaticId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | ||
67 | AttrDefId::TraitId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | 66 | AttrDefId::TraitId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), |
68 | AttrDefId::MacroDefId(it) => attrs_from_ast(it.ast_id, db), | 67 | AttrDefId::MacroDefId(it) => attrs_from_ast(it.ast_id, db), |
69 | AttrDefId::ImplId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), | 68 | AttrDefId::ImplId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), |
70 | AttrDefId::ConstId(it) => attrs_from_loc(it.lookup(db), db), | 69 | AttrDefId::ConstId(it) => attrs_from_loc(it.lookup(db), db), |
70 | AttrDefId::StaticId(it) => attrs_from_loc(it.lookup(db), db), | ||
71 | AttrDefId::FunctionId(it) => attrs_from_loc(it.lookup(db), db), | 71 | AttrDefId::FunctionId(it) => attrs_from_loc(it.lookup(db), db), |
72 | AttrDefId::TypeAliasId(it) => attrs_from_loc(it.lookup(db), db), | 72 | AttrDefId::TypeAliasId(it) => attrs_from_loc(it.lookup(db), db), |
73 | } | 73 | } |
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 225638b42..1589085b5 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -17,7 +17,7 @@ use crate::{ | |||
17 | expr::{Expr, ExprId, Pat, PatId}, | 17 | expr::{Expr, ExprId, Pat, PatId}, |
18 | nameres::CrateDefMap, | 18 | nameres::CrateDefMap, |
19 | path::Path, | 19 | path::Path, |
20 | AstItemDef, DefWithBodyId, HasModule, HasSource, Lookup, ModuleId, | 20 | DefWithBodyId, HasModule, HasSource, Lookup, ModuleId, |
21 | }; | 21 | }; |
22 | 22 | ||
23 | pub struct Expander { | 23 | pub struct Expander { |
@@ -160,6 +160,7 @@ impl Body { | |||
160 | (src.file_id, c.module(db), src.value.body()) | 160 | (src.file_id, c.module(db), src.value.body()) |
161 | } | 161 | } |
162 | DefWithBodyId::StaticId(s) => { | 162 | DefWithBodyId::StaticId(s) => { |
163 | let s = s.lookup(db); | ||
163 | let src = s.source(db); | 164 | let src = s.source(db); |
164 | (src.file_id, s.module(db), src.value.body()) | 165 | (src.file_id, s.module(db), src.value.body()) |
165 | } | 166 | } |
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index f0b3e198a..81a8ec18d 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -204,7 +204,7 @@ impl ConstData { | |||
204 | } | 204 | } |
205 | 205 | ||
206 | pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc<ConstData> { | 206 | pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc<ConstData> { |
207 | let node = konst.source(db).value; | 207 | let node = konst.lookup(db).source(db).value; |
208 | const_data_for(&node) | 208 | const_data_for(&node) |
209 | } | 209 | } |
210 | } | 210 | } |
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs index 7fec2e8c0..32adb11bd 100644 --- a/crates/ra_hir_def/src/db.rs +++ b/crates/ra_hir_def/src/db.rs | |||
@@ -18,7 +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, ItemLoc, ModuleId, StaticId, StructOrUnionId, TraitId, TypeAliasId, TypeAliasLoc, | 21 | ImplId, ItemLoc, ModuleId, StaticId, StaticLoc, StructOrUnionId, TraitId, TypeAliasId, |
22 | TypeAliasLoc, | ||
22 | }; | 23 | }; |
23 | 24 | ||
24 | #[salsa::query_group(InternDatabaseStorage)] | 25 | #[salsa::query_group(InternDatabaseStorage)] |
@@ -32,7 +33,7 @@ pub trait InternDatabase: SourceDatabase { | |||
32 | #[salsa::interned] | 33 | #[salsa::interned] |
33 | fn intern_const(&self, loc: ConstLoc) -> ConstId; | 34 | fn intern_const(&self, loc: ConstLoc) -> ConstId; |
34 | #[salsa::interned] | 35 | #[salsa::interned] |
35 | fn intern_static(&self, loc: ItemLoc<ast::StaticDef>) -> StaticId; | 36 | fn intern_static(&self, loc: StaticLoc) -> StaticId; |
36 | #[salsa::interned] | 37 | #[salsa::interned] |
37 | fn intern_trait(&self, loc: ItemLoc<ast::TraitDef>) -> TraitId; | 38 | fn intern_trait(&self, loc: ItemLoc<ast::TraitDef>) -> TraitId; |
38 | #[salsa::interned] | 39 | #[salsa::interned] |
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs index 69846fd1b..225511428 100644 --- a/crates/ra_hir_def/src/docs.rs +++ b/crates/ra_hir_def/src/docs.rs | |||
@@ -52,10 +52,10 @@ impl Documentation { | |||
52 | let src = it.parent.child_source(db); | 52 | let src = it.parent.child_source(db); |
53 | docs_from_ast(&src.value[it.local_id]) | 53 | docs_from_ast(&src.value[it.local_id]) |
54 | } | 54 | } |
55 | AttrDefId::StaticId(it) => docs_from_ast(&it.source(db).value), | ||
56 | AttrDefId::TraitId(it) => docs_from_ast(&it.source(db).value), | 55 | AttrDefId::TraitId(it) => docs_from_ast(&it.source(db).value), |
57 | AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id.to_node(db)), | 56 | AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id.to_node(db)), |
58 | AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value), | 57 | AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value), |
58 | AttrDefId::StaticId(it) => docs_from_ast(&it.lookup(db).source(db).value), | ||
59 | AttrDefId::FunctionId(it) => docs_from_ast(&it.lookup(db).source(db).value), | 59 | AttrDefId::FunctionId(it) => docs_from_ast(&it.lookup(db).source(db).value), |
60 | AttrDefId::TypeAliasId(it) => docs_from_ast(&it.lookup(db).source(db).value), | 60 | AttrDefId::TypeAliasId(it) => docs_from_ast(&it.lookup(db).source(db).value), |
61 | AttrDefId::ImplId(_) => None, | 61 | AttrDefId::ImplId(_) => None, |
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index b063530c2..89f1ceb58 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -245,12 +245,24 @@ impl Lookup for ConstId { | |||
245 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 245 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
246 | pub struct StaticId(salsa::InternId); | 246 | pub struct StaticId(salsa::InternId); |
247 | impl_intern_key!(StaticId); | 247 | impl_intern_key!(StaticId); |
248 | impl AstItemDef<ast::StaticDef> for StaticId { | 248 | |
249 | fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StaticDef>) -> Self { | 249 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
250 | db.intern_static(loc) | 250 | pub struct StaticLoc { |
251 | pub container: ModuleId, | ||
252 | pub ast_id: AstId<ast::StaticDef>, | ||
253 | } | ||
254 | |||
255 | impl Intern for StaticLoc { | ||
256 | type ID = StaticId; | ||
257 | fn intern(self, db: &impl db::DefDatabase) -> StaticId { | ||
258 | db.intern_static(self) | ||
251 | } | 259 | } |
252 | fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StaticDef> { | 260 | } |
253 | db.lookup_intern_static(self) | 261 | |
262 | impl Lookup for StaticId { | ||
263 | type Data = StaticLoc; | ||
264 | fn lookup(&self, db: &impl db::DefDatabase) -> StaticLoc { | ||
265 | db.lookup_intern_static(*self) | ||
254 | } | 266 | } |
255 | } | 267 | } |
256 | 268 | ||
@@ -481,6 +493,12 @@ impl HasModule for ConstLoc { | |||
481 | } | 493 | } |
482 | } | 494 | } |
483 | 495 | ||
496 | impl HasModule for StaticLoc { | ||
497 | fn module(&self, _db: &impl db::DefDatabase) -> ModuleId { | ||
498 | self.container | ||
499 | } | ||
500 | } | ||
501 | |||
484 | pub trait HasSource { | 502 | pub trait HasSource { |
485 | type Value; | 503 | type Value; |
486 | fn source(&self, db: &impl db::DefDatabase) -> Source<Self::Value>; | 504 | fn source(&self, db: &impl db::DefDatabase) -> Source<Self::Value>; |
@@ -513,6 +531,15 @@ impl HasSource for ConstLoc { | |||
513 | } | 531 | } |
514 | } | 532 | } |
515 | 533 | ||
534 | impl HasSource for StaticLoc { | ||
535 | type Value = ast::StaticDef; | ||
536 | |||
537 | fn source(&self, db: &impl db::DefDatabase) -> Source<ast::StaticDef> { | ||
538 | let node = self.ast_id.to_node(db); | ||
539 | Source::new(self.ast_id.file_id(), node) | ||
540 | } | ||
541 | } | ||
542 | |||
516 | pub trait HasChildSource { | 543 | pub trait HasChildSource { |
517 | type ChildId; | 544 | type ChildId; |
518 | type Value; | 545 | type Value; |
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 1d004b6a6..7b2487999 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -21,7 +21,7 @@ use crate::{ | |||
21 | path::{Path, PathKind}, | 21 | path::{Path, PathKind}, |
22 | per_ns::PerNs, | 22 | per_ns::PerNs, |
23 | AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId, | 23 | AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId, |
24 | Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, | 24 | Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId, |
25 | StructOrUnionId, TraitId, TypeAliasLoc, UnionId, | 25 | StructOrUnionId, TraitId, TypeAliasLoc, UnionId, |
26 | }; | 26 | }; |
27 | 27 | ||
@@ -715,7 +715,10 @@ where | |||
715 | PerNs::values(def.into()) | 715 | PerNs::values(def.into()) |
716 | } | 716 | } |
717 | raw::DefKind::Static(ast_id) => { | 717 | raw::DefKind::Static(ast_id) => { |
718 | PerNs::values(StaticId::from_ast_id(ctx, ast_id).into()) | 718 | let def = StaticLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) } |
719 | .intern(self.def_collector.db); | ||
720 | |||
721 | PerNs::values(def.into()) | ||
719 | } | 722 | } |
720 | raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()), | 723 | raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()), |
721 | raw::DefKind::TypeAlias(ast_id) => { | 724 | raw::DefKind::TypeAlias(ast_id) => { |
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index b56de44dd..4ff0a091b 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -540,7 +540,7 @@ impl HasResolver for ConstId { | |||
540 | 540 | ||
541 | impl HasResolver for StaticId { | 541 | impl HasResolver for StaticId { |
542 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 542 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
543 | self.module(db).resolver(db) | 543 | self.lookup(db).container.resolver(db) |
544 | } | 544 | } |
545 | } | 545 | } |
546 | 546 | ||