aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-12 13:25:59 +0000
committerGitHub <[email protected]>2019-12-12 13:25:59 +0000
commitd8dba7fbe587ba5fb6cfe939083ccd92c61f5827 (patch)
treec50b695604c7d418fc107775b9ec3a6845062751 /crates/ra_hir_def
parentb2638fcd2cc847e008e1dd7f1739283813b94026 (diff)
parent7b0644d81e52d00a7a6795b187f356213ff68225 (diff)
Merge #2537
2537: Switch to the new location for impls r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/attr.rs2
-rw-r--r--crates/ra_hir_def/src/child_by_source.rs5
-rw-r--r--crates/ra_hir_def/src/data.rs2
-rw-r--r--crates/ra_hir_def/src/db.rs6
-rw-r--r--crates/ra_hir_def/src/generics.rs2
-rw-r--r--crates/ra_hir_def/src/keys.rs6
-rw-r--r--crates/ra_hir_def/src/lib.rs30
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs10
-rw-r--r--crates/ra_hir_def/src/resolver.rs3
-rw-r--r--crates/ra_hir_def/src/src.rs11
10 files changed, 54 insertions, 23 deletions
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index 2f8f02d82..12d4e777a 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -64,7 +64,7 @@ impl Attrs {
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 }
67 AttrDefId::ImplId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), 67 AttrDefId::ImplId(it) => attrs_from_loc(it.lookup(db), db),
68 AttrDefId::ConstId(it) => attrs_from_loc(it.lookup(db), db), 68 AttrDefId::ConstId(it) => attrs_from_loc(it.lookup(db), db),
69 AttrDefId::StaticId(it) => attrs_from_loc(it.lookup(db), db), 69 AttrDefId::StaticId(it) => attrs_from_loc(it.lookup(db), db),
70 AttrDefId::FunctionId(it) => attrs_from_loc(it.lookup(db), db), 70 AttrDefId::FunctionId(it) => attrs_from_loc(it.lookup(db), db),
diff --git a/crates/ra_hir_def/src/child_by_source.rs b/crates/ra_hir_def/src/child_by_source.rs
index a3574a9db..821549bd5 100644
--- a/crates/ra_hir_def/src/child_by_source.rs
+++ b/crates/ra_hir_def/src/child_by_source.rs
@@ -98,6 +98,11 @@ impl ChildBySource for ModuleId {
98 } 98 }
99 } 99 }
100 100
101 for &impl_ in crate_def_map[self.local_id].impls.iter() {
102 let src = impl_.lookup(db).source(db);
103 res[keys::IMPL].insert(src, impl_)
104 }
105
101 res 106 res
102 } 107 }
103} 108}
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index 095d7064a..42821b9b1 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -167,7 +167,7 @@ pub struct ImplData {
167 167
168impl ImplData { 168impl ImplData {
169 pub(crate) fn impl_data_query(db: &impl DefDatabase, id: ImplId) -> Arc<ImplData> { 169 pub(crate) fn impl_data_query(db: &impl DefDatabase, id: ImplId) -> Arc<ImplData> {
170 let src = id.source(db); 170 let src = id.lookup(db).source(db);
171 let items = db.ast_id_map(src.file_id); 171 let items = db.ast_id_map(src.file_id);
172 172
173 let target_trait = src.value.target_trait().map(TypeRef::from_ast); 173 let target_trait = src.value.target_trait().map(TypeRef::from_ast);
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index ef5611ffc..8907aacca 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, ItemLoc, ModuleId, StaticId, StaticLoc, StructId, TraitId, TypeAliasId, TypeAliasLoc, 21 ImplId, ImplLoc, ItemLoc, ModuleId, StaticId, StaticLoc, StructId, TraitId, TypeAliasId,
22 UnionId, 22 TypeAliasLoc, UnionId,
23}; 23};
24 24
25#[salsa::query_group(InternDatabaseStorage)] 25#[salsa::query_group(InternDatabaseStorage)]
@@ -41,7 +41,7 @@ pub trait InternDatabase: SourceDatabase {
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]
44 fn intern_impl(&self, loc: ItemLoc<ast::ImplBlock>) -> ImplId; 44 fn intern_impl(&self, loc: ImplLoc) -> ImplId;
45} 45}
46 46
47#[salsa::query_group(DefDatabaseStorage)] 47#[salsa::query_group(DefDatabaseStorage)]
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index 976cf72d0..5d1100945 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -109,7 +109,7 @@ impl GenericParams {
109 // type-parameter, but rather is a type-alias for impl's target 109 // type-parameter, but rather is a type-alias for impl's target
110 // type, so this is handled by the resolver. 110 // type, so this is handled by the resolver.
111 GenericDefId::ImplId(it) => { 111 GenericDefId::ImplId(it) => {
112 let src = it.source(db); 112 let src = it.lookup(db).source(db);
113 generics.fill(&mut sm, &src.value); 113 generics.fill(&mut sm, &src.value);
114 src.file_id 114 src.file_id
115 } 115 }
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs
index be702a4f8..d318b2451 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, TypeParamId, 11 ConstId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, TypeAliasId, TypeParamId,
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>>;
@@ -16,8 +16,10 @@ type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>;
16pub const FUNCTION: Key<ast::FnDef, FunctionId> = Key::new(); 16pub const FUNCTION: Key<ast::FnDef, FunctionId> = Key::new();
17pub const CONST: Key<ast::ConstDef, ConstId> = Key::new(); 17pub const CONST: Key<ast::ConstDef, ConstId> = Key::new();
18pub const STATIC: Key<ast::StaticDef, StaticId> = Key::new(); 18pub const STATIC: Key<ast::StaticDef, StaticId> = Key::new();
19pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new();
20pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new(); 19pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new();
20pub const IMPL: Key<ast::ImplBlock, ImplId> = Key::new();
21
22pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new();
21pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); 23pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new();
22pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new(); 24pub const RECORD_FIELD: Key<ast::RecordFieldDef, StructFieldId> = Key::new();
23pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new(); 25pub const TYPE_PARAM: Key<ast::TypeParam, TypeParamId> = Key::new();
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 569da4f28..5564b166b 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -289,12 +289,24 @@ impl Lookup for TypeAliasId {
289#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 289#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
290pub struct ImplId(salsa::InternId); 290pub struct ImplId(salsa::InternId);
291impl_intern_key!(ImplId); 291impl_intern_key!(ImplId);
292impl AstItemDef<ast::ImplBlock> for ImplId { 292
293 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::ImplBlock>) -> Self { 293#[derive(Debug, Clone, PartialEq, Eq, Hash)]
294 db.intern_impl(loc) 294pub struct ImplLoc {
295 pub container: ModuleId,
296 pub ast_id: AstId<ast::ImplBlock>,
297}
298
299impl Intern for ImplLoc {
300 type ID = ImplId;
301 fn intern(self, db: &impl db::DefDatabase) -> ImplId {
302 db.intern_impl(self)
295 } 303 }
296 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::ImplBlock> { 304}
297 db.lookup_intern_impl(self) 305
306impl Lookup for ImplId {
307 type Data = ImplLoc;
308 fn lookup(&self, db: &impl db::DefDatabase) -> ImplLoc {
309 db.lookup_intern_impl(*self)
298 } 310 }
299} 311}
300 312
@@ -479,7 +491,7 @@ impl HasModule for FunctionLoc {
479 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 491 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
480 match self.container { 492 match self.container {
481 ContainerId::ModuleId(it) => it, 493 ContainerId::ModuleId(it) => it,
482 ContainerId::ImplId(it) => it.module(db), 494 ContainerId::ImplId(it) => it.lookup(db).container,
483 ContainerId::TraitId(it) => it.module(db), 495 ContainerId::TraitId(it) => it.module(db),
484 } 496 }
485 } 497 }
@@ -489,7 +501,7 @@ impl HasModule for TypeAliasLoc {
489 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 501 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
490 match self.container { 502 match self.container {
491 ContainerId::ModuleId(it) => it, 503 ContainerId::ModuleId(it) => it,
492 ContainerId::ImplId(it) => it.module(db), 504 ContainerId::ImplId(it) => it.lookup(db).container,
493 ContainerId::TraitId(it) => it.module(db), 505 ContainerId::TraitId(it) => it.module(db),
494 } 506 }
495 } 507 }
@@ -499,7 +511,7 @@ impl HasModule for ConstLoc {
499 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 511 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
500 match self.container { 512 match self.container {
501 ContainerId::ModuleId(it) => it, 513 ContainerId::ModuleId(it) => it,
502 ContainerId::ImplId(it) => it.module(db), 514 ContainerId::ImplId(it) => it.lookup(db).container,
503 ContainerId::TraitId(it) => it.module(db), 515 ContainerId::TraitId(it) => it.module(db),
504 } 516 }
505 } 517 }
@@ -532,7 +544,7 @@ impl HasModule for GenericDefId {
532 GenericDefId::AdtId(it) => it.module(db), 544 GenericDefId::AdtId(it) => it.module(db),
533 GenericDefId::TraitId(it) => it.module(db), 545 GenericDefId::TraitId(it) => it.module(db),
534 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), 546 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
535 GenericDefId::ImplId(it) => it.module(db), 547 GenericDefId::ImplId(it) => it.lookup(db).container,
536 GenericDefId::EnumVariantId(it) => it.parent.module(db), 548 GenericDefId::EnumVariantId(it) => it.parent.module(db),
537 GenericDefId::ConstId(it) => it.lookup(db).module(db), 549 GenericDefId::ConstId(it) => it.lookup(db).module(db),
538 } 550 }
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index a80067979..b33507a9a 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -24,7 +24,7 @@ use crate::{
24 }, 24 },
25 path::{Path, PathKind}, 25 path::{Path, PathKind},
26 per_ns::PerNs, 26 per_ns::PerNs,
27 AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId, 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 TraitId, TypeAliasLoc, UnionId,
30}; 30};
@@ -661,9 +661,11 @@ where
661 krate: self.def_collector.def_map.krate, 661 krate: self.def_collector.def_map.krate,
662 local_id: self.module_id, 662 local_id: self.module_id,
663 }; 663 };
664 let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id); 664 let ast_id = self.raw_items[imp].ast_id;
665 let imp_id = ImplId::from_ast_id(ctx, self.raw_items[imp].ast_id); 665 let impl_id =
666 self.def_collector.def_map.modules[self.module_id].impls.push(imp_id) 666 ImplLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) }
667 .intern(self.def_collector.db);
668 self.def_collector.def_map.modules[self.module_id].impls.push(impl_id)
667 } 669 }
668 } 670 }
669 } 671 }
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index 9484a61d5..f87b16b44 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -564,7 +564,8 @@ impl HasResolver for TypeAliasId {
564 564
565impl HasResolver for ImplId { 565impl HasResolver for ImplId {
566 fn resolver(self, db: &impl DefDatabase) -> Resolver { 566 fn resolver(self, db: &impl DefDatabase) -> Resolver {
567 self.module(db) 567 self.lookup(db)
568 .container
568 .resolver(db) 569 .resolver(db)
569 .push_generic_params_scope(db, self.into()) 570 .push_generic_params_scope(db, self.into())
570 .push_impl_block_scope(self) 571 .push_impl_block_scope(self)
diff --git a/crates/ra_hir_def/src/src.rs b/crates/ra_hir_def/src/src.rs
index 27caa02cc..a5c4359a7 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, StaticLoc, TypeAliasLoc}; 7use crate::{db::DefDatabase, ConstLoc, FunctionLoc, ImplLoc, StaticLoc, TypeAliasLoc};
8 8
9pub trait HasSource { 9pub trait HasSource {
10 type Value; 10 type Value;
@@ -47,6 +47,15 @@ impl HasSource for StaticLoc {
47 } 47 }
48} 48}
49 49
50impl HasSource for ImplLoc {
51 type Value = ast::ImplBlock;
52
53 fn source(&self, db: &impl DefDatabase) -> InFile<ast::ImplBlock> {
54 let node = self.ast_id.to_node(db);
55 InFile::new(self.ast_id.file_id, node)
56 }
57}
58
50pub trait HasChildSource { 59pub trait HasChildSource {
51 type ChildId; 60 type ChildId;
52 type Value; 61 type Value;