aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/impls.rs8
-rw-r--r--crates/ra_hir_def/src/lib.rs37
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs8
-rw-r--r--crates/ra_hir_def/src/traits.rs8
4 files changed, 27 insertions, 34 deletions
diff --git a/crates/ra_hir_def/src/impls.rs b/crates/ra_hir_def/src/impls.rs
index 703e4d503..574086ac7 100644
--- a/crates/ra_hir_def/src/impls.rs
+++ b/crates/ra_hir_def/src/impls.rs
@@ -9,8 +9,8 @@ use hir_expand::AstId;
9use ra_syntax::ast; 9use ra_syntax::ast;
10 10
11use crate::{ 11use crate::{
12 db::DefDatabase2, type_ref::TypeRef, AssocItemId, AstItemDef, ConstId, FunctionContainerId, 12 db::DefDatabase2, type_ref::TypeRef, AssocItemId, AstItemDef, ConstId, ContainerId,
13 FunctionLoc, ImplId, Intern, LocationCtx, TypeAliasContainerId, TypeAliasLoc, 13 FunctionLoc, ImplId, Intern, LocationCtx, TypeAliasLoc,
14}; 14};
15 15
16#[derive(Debug, Clone, PartialEq, Eq)] 16#[derive(Debug, Clone, PartialEq, Eq)]
@@ -37,7 +37,7 @@ impl ImplData {
37 .map(|item_node| match item_node { 37 .map(|item_node| match item_node {
38 ast::ImplItem::FnDef(it) => { 38 ast::ImplItem::FnDef(it) => {
39 let def = FunctionLoc { 39 let def = FunctionLoc {
40 container: FunctionContainerId::ImplId(id), 40 container: ContainerId::ImplId(id),
41 ast_id: AstId::new(src.file_id, items.ast_id(&it)), 41 ast_id: AstId::new(src.file_id, items.ast_id(&it)),
42 } 42 }
43 .intern(db); 43 .intern(db);
@@ -48,7 +48,7 @@ impl ImplData {
48 } 48 }
49 ast::ImplItem::TypeAliasDef(it) => { 49 ast::ImplItem::TypeAliasDef(it) => {
50 let def = TypeAliasLoc { 50 let def = TypeAliasLoc {
51 container: TypeAliasContainerId::ImplId(id), 51 container: ContainerId::ImplId(id),
52 ast_id: AstId::new(src.file_id, items.ast_id(&it)), 52 ast_id: AstId::new(src.file_id, items.ast_id(&it)),
53 } 53 }
54 .intern(db); 54 .intern(db);
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 6052370b4..da6506fcd 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -201,7 +201,7 @@ impl_intern_key!(FunctionId);
201 201
202#[derive(Debug, Clone, PartialEq, Eq, Hash)] 202#[derive(Debug, Clone, PartialEq, Eq, Hash)]
203pub struct FunctionLoc { 203pub struct FunctionLoc {
204 pub container: FunctionContainerId, 204 pub container: ContainerId,
205 pub ast_id: AstId<ast::FnDef>, 205 pub ast_id: AstId<ast::FnDef>,
206} 206}
207 207
@@ -220,13 +220,6 @@ impl Lookup for FunctionId {
220} 220}
221 221
222#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 222#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
223pub enum FunctionContainerId {
224 ModuleId(ModuleId),
225 ImplId(ImplId),
226 TraitId(TraitId),
227}
228
229#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
230pub struct StructOrUnionId(salsa::InternId); 223pub struct StructOrUnionId(salsa::InternId);
231impl_intern_key!(StructOrUnionId); 224impl_intern_key!(StructOrUnionId);
232impl AstItemDef<ast::StructDef> for StructOrUnionId { 225impl AstItemDef<ast::StructDef> for StructOrUnionId {
@@ -335,7 +328,7 @@ impl_intern_key!(TypeAliasId);
335 328
336#[derive(Debug, Clone, PartialEq, Eq, Hash)] 329#[derive(Debug, Clone, PartialEq, Eq, Hash)]
337pub struct TypeAliasLoc { 330pub struct TypeAliasLoc {
338 pub container: TypeAliasContainerId, 331 pub container: ContainerId,
339 pub ast_id: AstId<ast::TypeAliasDef>, 332 pub ast_id: AstId<ast::TypeAliasDef>,
340} 333}
341 334
@@ -354,13 +347,6 @@ impl Lookup for TypeAliasId {
354} 347}
355 348
356#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 349#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
357pub enum TypeAliasContainerId {
358 ModuleId(ModuleId),
359 ImplId(ImplId),
360 TraitId(TraitId),
361}
362
363#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
364pub struct ImplId(salsa::InternId); 350pub struct ImplId(salsa::InternId);
365impl_intern_key!(ImplId); 351impl_intern_key!(ImplId);
366impl AstItemDef<ast::ImplBlock> for ImplId { 352impl AstItemDef<ast::ImplBlock> for ImplId {
@@ -391,6 +377,13 @@ macro_rules! impl_froms {
391 } 377 }
392} 378}
393 379
380#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
381pub enum ContainerId {
382 ModuleId(ModuleId),
383 ImplId(ImplId),
384 TraitId(TraitId),
385}
386
394/// A Data Type 387/// A Data Type
395#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 388#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
396pub enum AdtId { 389pub enum AdtId {
@@ -488,9 +481,9 @@ pub trait HasModule {
488impl HasModule for FunctionLoc { 481impl HasModule for FunctionLoc {
489 fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { 482 fn module(&self, db: &impl db::DefDatabase2) -> ModuleId {
490 match self.container { 483 match self.container {
491 FunctionContainerId::ModuleId(it) => it, 484 ContainerId::ModuleId(it) => it,
492 FunctionContainerId::ImplId(it) => it.module(db), 485 ContainerId::ImplId(it) => it.module(db),
493 FunctionContainerId::TraitId(it) => it.module(db), 486 ContainerId::TraitId(it) => it.module(db),
494 } 487 }
495 } 488 }
496} 489}
@@ -498,9 +491,9 @@ impl HasModule for FunctionLoc {
498impl HasModule for TypeAliasLoc { 491impl HasModule for TypeAliasLoc {
499 fn module(&self, db: &impl db::DefDatabase2) -> ModuleId { 492 fn module(&self, db: &impl db::DefDatabase2) -> ModuleId {
500 match self.container { 493 match self.container {
501 TypeAliasContainerId::ModuleId(it) => it, 494 ContainerId::ModuleId(it) => it,
502 TypeAliasContainerId::ImplId(it) => it.module(db), 495 ContainerId::ImplId(it) => it.module(db),
503 TypeAliasContainerId::TraitId(it) => it.module(db), 496 ContainerId::TraitId(it) => it.module(db),
504 } 497 }
505 } 498 }
506} 499}
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 060185b61..71e01279d 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -19,9 +19,9 @@ use crate::{
19 per_ns::PerNs, raw, CrateDefMap, ModuleData, Resolution, ResolveMode, 19 per_ns::PerNs, raw, CrateDefMap, ModuleData, Resolution, ResolveMode,
20 }, 20 },
21 path::{Path, PathKind}, 21 path::{Path, PathKind},
22 AdtId, AstId, AstItemDef, ConstId, CrateModuleId, EnumId, EnumVariantId, FunctionContainerId, 22 AdtId, AstId, AstItemDef, ConstId, ContainerId, CrateModuleId, EnumId, EnumVariantId,
23 FunctionLoc, ImplId, Intern, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, 23 FunctionLoc, ImplId, Intern, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId,
24 StructOrUnionId, TraitId, TypeAliasContainerId, TypeAliasLoc, UnionId, 24 StructOrUnionId, TraitId, TypeAliasLoc, UnionId,
25}; 25};
26 26
27pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> CrateDefMap { 27pub(super) fn collect_defs(db: &impl DefDatabase2, mut def_map: CrateDefMap) -> CrateDefMap {
@@ -674,7 +674,7 @@ where
674 let def: PerNs = match def.kind { 674 let def: PerNs = match def.kind {
675 raw::DefKind::Function(ast_id) => { 675 raw::DefKind::Function(ast_id) => {
676 let def = FunctionLoc { 676 let def = FunctionLoc {
677 container: FunctionContainerId::ModuleId(module), 677 container: ContainerId::ModuleId(module),
678 ast_id: AstId::new(self.file_id, ast_id), 678 ast_id: AstId::new(self.file_id, ast_id),
679 } 679 }
680 .intern(self.def_collector.db); 680 .intern(self.def_collector.db);
@@ -699,7 +699,7 @@ where
699 raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()), 699 raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()),
700 raw::DefKind::TypeAlias(ast_id) => { 700 raw::DefKind::TypeAlias(ast_id) => {
701 let def = TypeAliasLoc { 701 let def = TypeAliasLoc {
702 container: TypeAliasContainerId::ModuleId(module), 702 container: ContainerId::ModuleId(module),
703 ast_id: AstId::new(self.file_id, ast_id), 703 ast_id: AstId::new(self.file_id, ast_id),
704 } 704 }
705 .intern(self.def_collector.db); 705 .intern(self.def_collector.db);
diff --git a/crates/ra_hir_def/src/traits.rs b/crates/ra_hir_def/src/traits.rs
index 228524a57..bb61e852a 100644
--- a/crates/ra_hir_def/src/traits.rs
+++ b/crates/ra_hir_def/src/traits.rs
@@ -11,8 +11,8 @@ use ra_syntax::ast::{self, NameOwner};
11use rustc_hash::FxHashMap; 11use rustc_hash::FxHashMap;
12 12
13use crate::{ 13use crate::{
14 db::DefDatabase2, AssocItemId, AstItemDef, ConstId, FunctionContainerId, FunctionLoc, Intern, 14 db::DefDatabase2, AssocItemId, AstItemDef, ConstId, ContainerId, FunctionLoc, Intern,
15 LocationCtx, ModuleDefId, ModuleId, TraitId, TypeAliasContainerId, TypeAliasLoc, 15 LocationCtx, ModuleDefId, ModuleId, TraitId, TypeAliasLoc,
16}; 16};
17 17
18#[derive(Debug, Clone, PartialEq, Eq)] 18#[derive(Debug, Clone, PartialEq, Eq)]
@@ -35,14 +35,14 @@ impl TraitData {
35 .impl_items() 35 .impl_items()
36 .map(|item_node| match item_node { 36 .map(|item_node| match item_node {
37 ast::ImplItem::FnDef(it) => FunctionLoc { 37 ast::ImplItem::FnDef(it) => FunctionLoc {
38 container: FunctionContainerId::TraitId(tr), 38 container: ContainerId::TraitId(tr),
39 ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), 39 ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)),
40 } 40 }
41 .intern(db) 41 .intern(db)
42 .into(), 42 .into(),
43 ast::ImplItem::ConstDef(it) => ConstId::from_ast(ctx, &it).into(), 43 ast::ImplItem::ConstDef(it) => ConstId::from_ast(ctx, &it).into(),
44 ast::ImplItem::TypeAliasDef(it) => TypeAliasLoc { 44 ast::ImplItem::TypeAliasDef(it) => TypeAliasLoc {
45 container: TypeAliasContainerId::TraitId(tr), 45 container: ContainerId::TraitId(tr),
46 ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), 46 ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)),
47 } 47 }
48 .intern(db) 48 .intern(db)