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/adt.rs13
-rw-r--r--crates/ra_hir_def/src/attr.rs7
-rw-r--r--crates/ra_hir_def/src/child_by_source.rs10
-rw-r--r--crates/ra_hir_def/src/db.rs12
-rw-r--r--crates/ra_hir_def/src/docs.rs6
-rw-r--r--crates/ra_hir_def/src/generics.rs6
-rw-r--r--crates/ra_hir_def/src/keys.rs4
-rw-r--r--crates/ra_hir_def/src/lib.rs50
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs19
-rw-r--r--crates/ra_hir_def/src/src.rs21
10 files changed, 100 insertions, 48 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index ef2b20f1e..ec3d57d1a 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -11,9 +11,8 @@ use ra_arena::{map::ArenaMap, Arena};
11use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; 11use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
12 12
13use crate::{ 13use crate::{
14 db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, type_ref::TypeRef, 14 db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, type_ref::TypeRef, EnumId,
15 AstItemDef, EnumId, LocalEnumVariantId, LocalStructFieldId, Lookup, StructId, UnionId, 15 LocalEnumVariantId, LocalStructFieldId, Lookup, StructId, UnionId, VariantId,
16 VariantId,
17}; 16};
18 17
19/// Note that we use `StructData` for unions as well! 18/// Note that we use `StructData` for unions as well!
@@ -58,7 +57,7 @@ impl StructData {
58 Arc::new(StructData { name, variant_data }) 57 Arc::new(StructData { name, variant_data })
59 } 58 }
60 pub(crate) fn union_data_query(db: &impl DefDatabase, id: UnionId) -> Arc<StructData> { 59 pub(crate) fn union_data_query(db: &impl DefDatabase, id: UnionId) -> Arc<StructData> {
61 let src = id.source(db); 60 let src = id.lookup(db).source(db);
62 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); 61 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
63 let variant_data = VariantData::new( 62 let variant_data = VariantData::new(
64 src.value 63 src.value
@@ -73,7 +72,7 @@ impl StructData {
73 72
74impl EnumData { 73impl EnumData {
75 pub(crate) fn enum_data_query(db: &impl DefDatabase, e: EnumId) -> Arc<EnumData> { 74 pub(crate) fn enum_data_query(db: &impl DefDatabase, e: EnumId) -> Arc<EnumData> {
76 let src = e.source(db); 75 let src = e.lookup(db).source(db);
77 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); 76 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
78 let mut trace = Trace::new_for_arena(); 77 let mut trace = Trace::new_for_arena();
79 lower_enum(&mut trace, &src.value); 78 lower_enum(&mut trace, &src.value);
@@ -90,7 +89,7 @@ impl HasChildSource for EnumId {
90 type ChildId = LocalEnumVariantId; 89 type ChildId = LocalEnumVariantId;
91 type Value = ast::EnumVariant; 90 type Value = ast::EnumVariant;
92 fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { 91 fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
93 let src = self.source(db); 92 let src = self.lookup(db).source(db);
94 let mut trace = Trace::new_for_map(); 93 let mut trace = Trace::new_for_map();
95 lower_enum(&mut trace, &src.value); 94 lower_enum(&mut trace, &src.value);
96 src.with_value(trace.into_map()) 95 src.with_value(trace.into_map())
@@ -155,7 +154,7 @@ impl HasChildSource for VariantId {
155 src.map(|map| map[it.local_id].kind()) 154 src.map(|map| map[it.local_id].kind())
156 } 155 }
157 VariantId::StructId(it) => it.lookup(db).source(db).map(|it| it.kind()), 156 VariantId::StructId(it) => it.lookup(db).source(db).map(|it| it.kind()),
158 VariantId::UnionId(it) => it.source(db).map(|it| { 157 VariantId::UnionId(it) => it.lookup(db).source(db).map(|it| {
159 it.record_field_def_list() 158 it.record_field_def_list()
160 .map(ast::StructKind::Record) 159 .map(ast::StructKind::Record)
161 .unwrap_or(ast::StructKind::Unit) 160 .unwrap_or(ast::StructKind::Unit)
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index d2aa5ce8f..5bf82e191 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -12,8 +12,7 @@ use ra_syntax::{
12use tt::Subtree; 12use tt::Subtree;
13 13
14use crate::{ 14use crate::{
15 db::DefDatabase, path::Path, src::HasChildSource, src::HasSource, AdtId, AstItemDef, AttrDefId, 15 db::DefDatabase, path::Path, src::HasChildSource, src::HasSource, AdtId, AttrDefId, Lookup,
16 Lookup,
17}; 16};
18 17
19#[derive(Default, Debug, Clone, PartialEq, Eq)] 18#[derive(Default, Debug, Clone, PartialEq, Eq)]
@@ -57,8 +56,8 @@ impl Attrs {
57 } 56 }
58 AttrDefId::AdtId(it) => match it { 57 AttrDefId::AdtId(it) => match it {
59 AdtId::StructId(it) => attrs_from_loc(it.lookup(db), db), 58 AdtId::StructId(it) => attrs_from_loc(it.lookup(db), db),
60 AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), 59 AdtId::EnumId(it) => attrs_from_loc(it.lookup(db), db),
61 AdtId::UnionId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), 60 AdtId::UnionId(it) => attrs_from_loc(it.lookup(db), db),
62 }, 61 },
63 AttrDefId::TraitId(it) => attrs_from_loc(it.lookup(db), db), 62 AttrDefId::TraitId(it) => attrs_from_loc(it.lookup(db), db),
64 AttrDefId::MacroDefId(it) => { 63 AttrDefId::MacroDefId(it) => {
diff --git a/crates/ra_hir_def/src/child_by_source.rs b/crates/ra_hir_def/src/child_by_source.rs
index eba361578..3c9379b15 100644
--- a/crates/ra_hir_def/src/child_by_source.rs
+++ b/crates/ra_hir_def/src/child_by_source.rs
@@ -103,8 +103,14 @@ impl ChildBySource for ModuleId {
103 let src = strukt.lookup(db).source(db); 103 let src = strukt.lookup(db).source(db);
104 res[keys::STRUCT].insert(src, strukt) 104 res[keys::STRUCT].insert(src, strukt)
105 } 105 }
106 AdtId::UnionId(_) => (), 106 AdtId::UnionId(union_) => {
107 AdtId::EnumId(_) => (), 107 let src = union_.lookup(db).source(db);
108 res[keys::UNION].insert(src, union_)
109 }
110 AdtId::EnumId(enum_) => {
111 let src = enum_.lookup(db).source(db);
112 res[keys::ENUM].insert(src, enum_)
113 }
108 }, 114 },
109 _ => (), 115 _ => (),
110 } 116 }
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index e120c7768..98bff6cb7 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
3 3
4use hir_expand::{db::AstDatabase, HirFileId}; 4use hir_expand::{db::AstDatabase, HirFileId};
5use ra_db::{salsa, CrateId, SourceDatabase}; 5use ra_db::{salsa, CrateId, SourceDatabase};
6use ra_syntax::{ast, SmolStr}; 6use ra_syntax::SmolStr;
7 7
8use crate::{ 8use crate::{
9 adt::{EnumData, StructData}, 9 adt::{EnumData, StructData},
@@ -17,9 +17,9 @@ use crate::{
17 raw::{ImportSourceMap, RawItems}, 17 raw::{ImportSourceMap, RawItems},
18 CrateDefMap, 18 CrateDefMap,
19 }, 19 },
20 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, FunctionId, FunctionLoc, GenericDefId, 20 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, EnumLoc, FunctionId, FunctionLoc,
21 ImplId, ImplLoc, ItemLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId, 21 GenericDefId, ImplId, ImplLoc, ModuleId, StaticId, StaticLoc, StructId, StructLoc, TraitId,
22 TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, 22 TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc,
23}; 23};
24 24
25#[salsa::query_group(InternDatabaseStorage)] 25#[salsa::query_group(InternDatabaseStorage)]
@@ -29,9 +29,9 @@ pub trait InternDatabase: SourceDatabase {
29 #[salsa::interned] 29 #[salsa::interned]
30 fn intern_struct(&self, loc: StructLoc) -> StructId; 30 fn intern_struct(&self, loc: StructLoc) -> StructId;
31 #[salsa::interned] 31 #[salsa::interned]
32 fn intern_union(&self, loc: ItemLoc<ast::UnionDef>) -> UnionId; 32 fn intern_union(&self, loc: UnionLoc) -> UnionId;
33 #[salsa::interned] 33 #[salsa::interned]
34 fn intern_enum(&self, loc: ItemLoc<ast::EnumDef>) -> EnumId; 34 fn intern_enum(&self, loc: EnumLoc) -> EnumId;
35 #[salsa::interned] 35 #[salsa::interned]
36 fn intern_const(&self, loc: ConstLoc) -> ConstId; 36 fn intern_const(&self, loc: ConstLoc) -> ConstId;
37 #[salsa::interned] 37 #[salsa::interned]
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs
index 58143b894..b29f142e3 100644
--- a/crates/ra_hir_def/src/docs.rs
+++ b/crates/ra_hir_def/src/docs.rs
@@ -11,7 +11,7 @@ use ra_syntax::ast;
11use crate::{ 11use crate::{
12 db::DefDatabase, 12 db::DefDatabase,
13 src::{HasChildSource, HasSource}, 13 src::{HasChildSource, HasSource},
14 AdtId, AstItemDef, AttrDefId, Lookup, 14 AdtId, AttrDefId, Lookup,
15}; 15};
16 16
17/// Holds documentation 17/// Holds documentation
@@ -52,8 +52,8 @@ impl Documentation {
52 } 52 }
53 AttrDefId::AdtId(it) => match it { 53 AttrDefId::AdtId(it) => match it {
54 AdtId::StructId(it) => docs_from_ast(&it.lookup(db).source(db).value), 54 AdtId::StructId(it) => docs_from_ast(&it.lookup(db).source(db).value),
55 AdtId::EnumId(it) => docs_from_ast(&it.source(db).value), 55 AdtId::EnumId(it) => docs_from_ast(&it.lookup(db).source(db).value),
56 AdtId::UnionId(it) => docs_from_ast(&it.source(db).value), 56 AdtId::UnionId(it) => docs_from_ast(&it.lookup(db).source(db).value),
57 }, 57 },
58 AttrDefId::EnumVariantId(it) => { 58 AttrDefId::EnumVariantId(it) => {
59 let src = it.parent.child_source(db); 59 let src = it.parent.child_source(db);
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index f1ce8d59a..e502dd798 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -21,7 +21,7 @@ use crate::{
21 src::HasChildSource, 21 src::HasChildSource,
22 src::HasSource, 22 src::HasSource,
23 type_ref::{TypeBound, TypeRef}, 23 type_ref::{TypeBound, TypeRef},
24 AdtId, AstItemDef, GenericDefId, LocalTypeParamId, Lookup, TypeParamId, 24 AdtId, GenericDefId, LocalTypeParamId, Lookup, TypeParamId,
25}; 25};
26 26
27/// Data about a generic parameter (to a function, struct, impl, ...). 27/// Data about a generic parameter (to a function, struct, impl, ...).
@@ -76,12 +76,12 @@ impl GenericParams {
76 src.file_id 76 src.file_id
77 } 77 }
78 GenericDefId::AdtId(AdtId::UnionId(it)) => { 78 GenericDefId::AdtId(AdtId::UnionId(it)) => {
79 let src = it.source(db); 79 let src = it.lookup(db).source(db);
80 generics.fill(&mut sm, &src.value); 80 generics.fill(&mut sm, &src.value);
81 src.file_id 81 src.file_id
82 } 82 }
83 GenericDefId::AdtId(AdtId::EnumId(it)) => { 83 GenericDefId::AdtId(AdtId::EnumId(it)) => {
84 let src = it.source(db); 84 let src = it.lookup(db).source(db);
85 generics.fill(&mut sm, &src.value); 85 generics.fill(&mut sm, &src.value);
86 src.file_id 86 src.file_id
87 } 87 }
diff --git a/crates/ra_hir_def/src/keys.rs b/crates/ra_hir_def/src/keys.rs
index 758cf8097..ada145379 100644
--- a/crates/ra_hir_def/src/keys.rs
+++ b/crates/ra_hir_def/src/keys.rs
@@ -9,7 +9,7 @@ use rustc_hash::FxHashMap;
9use crate::{ 9use crate::{
10 dyn_map::{DynMap, Policy}, 10 dyn_map::{DynMap, Policy},
11 ConstId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, StructId, TraitId, 11 ConstId, EnumVariantId, FunctionId, ImplId, StaticId, StructFieldId, StructId, TraitId,
12 TypeAliasId, TypeParamId, 12 TypeAliasId, TypeParamId, EnumId, UnionId,
13}; 13};
14 14
15type 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>>;
@@ -21,6 +21,8 @@ pub const TYPE_ALIAS: Key<ast::TypeAliasDef, TypeAliasId> = Key::new();
21pub 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(); 22pub const TRAIT: Key<ast::TraitDef, TraitId> = Key::new();
23pub const STRUCT: Key<ast::StructDef, StructId> = Key::new(); 23pub const STRUCT: Key<ast::StructDef, StructId> = Key::new();
24pub const UNION: Key<ast::UnionDef, UnionId> = Key::new();
25pub const ENUM: Key<ast::EnumDef, EnumId> = Key::new();
24 26
25pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new(); 27pub const ENUM_VARIANT: Key<ast::EnumVariant, EnumVariantId> = Key::new();
26pub const TUPLE_FIELD: Key<ast::TupleFieldDef, StructFieldId> = Key::new(); 28pub 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 1a599706a..c9e4e6a0f 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -173,24 +173,48 @@ impl Lookup for StructId {
173#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 173#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
174pub struct UnionId(salsa::InternId); 174pub struct UnionId(salsa::InternId);
175impl_intern_key!(UnionId); 175impl_intern_key!(UnionId);
176impl AstItemDef<ast::UnionDef> for UnionId { 176
177 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::UnionDef>) -> Self { 177#[derive(Debug, Clone, PartialEq, Eq, Hash)]
178 db.intern_union(loc) 178pub struct UnionLoc {
179 pub container: ModuleId,
180 pub ast_id: AstId<ast::UnionDef>,
181}
182
183impl Intern for UnionLoc {
184 type ID = UnionId;
185 fn intern(self, db: &impl db::DefDatabase) -> UnionId {
186 db.intern_union(self)
179 } 187 }
180 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::UnionDef> { 188}
181 db.lookup_intern_union(self) 189
190impl Lookup for UnionId {
191 type Data = UnionLoc;
192 fn lookup(&self, db: &impl db::DefDatabase) -> UnionLoc {
193 db.lookup_intern_union(*self)
182 } 194 }
183} 195}
184 196
185#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 197#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
186pub struct EnumId(salsa::InternId); 198pub struct EnumId(salsa::InternId);
187impl_intern_key!(EnumId); 199impl_intern_key!(EnumId);
188impl AstItemDef<ast::EnumDef> for EnumId { 200
189 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::EnumDef>) -> Self { 201#[derive(Debug, Clone, PartialEq, Eq, Hash)]
190 db.intern_enum(loc) 202pub struct EnumLoc {
203 pub container: ModuleId,
204 pub ast_id: AstId<ast::EnumDef>,
205}
206
207impl Intern for EnumLoc {
208 type ID = EnumId;
209 fn intern(self, db: &impl db::DefDatabase) -> EnumId {
210 db.intern_enum(self)
191 } 211 }
192 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::EnumDef> { 212}
193 db.lookup_intern_enum(self) 213
214impl Lookup for EnumId {
215 type Data = EnumLoc;
216 fn lookup(&self, db: &impl db::DefDatabase) -> EnumLoc {
217 db.lookup_intern_enum(*self)
194 } 218 }
195} 219}
196 220
@@ -545,8 +569,8 @@ impl HasModule for AdtId {
545 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 569 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
546 match self { 570 match self {
547 AdtId::StructId(it) => it.lookup(db).container, 571 AdtId::StructId(it) => it.lookup(db).container,
548 AdtId::UnionId(it) => it.module(db), 572 AdtId::UnionId(it) => it.lookup(db).container,
549 AdtId::EnumId(it) => it.module(db), 573 AdtId::EnumId(it) => it.lookup(db).container,
550 } 574 }
551 } 575 }
552} 576}
@@ -569,7 +593,7 @@ impl HasModule for GenericDefId {
569 GenericDefId::TraitId(it) => it.lookup(db).container, 593 GenericDefId::TraitId(it) => it.lookup(db).container,
570 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db), 594 GenericDefId::TypeAliasId(it) => it.lookup(db).module(db),
571 GenericDefId::ImplId(it) => it.lookup(db).container, 595 GenericDefId::ImplId(it) => it.lookup(db).container,
572 GenericDefId::EnumVariantId(it) => it.parent.module(db), 596 GenericDefId::EnumVariantId(it) => it.parent.lookup(db).container,
573 GenericDefId::ConstId(it) => it.lookup(db).module(db), 597 GenericDefId::ConstId(it) => it.lookup(db).module(db),
574 } 598 }
575 } 599 }
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 602ec0911..04aadead1 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -24,9 +24,9 @@ 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, ImplLoc, 27 AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
28 Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructLoc, 28 LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc,
29 TraitLoc, TypeAliasLoc, UnionId, 29 TypeAliasLoc, UnionLoc,
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 {
@@ -753,8 +753,6 @@ where
753 753
754 fn define_def(&mut self, def: &raw::DefData, attrs: &Attrs) { 754 fn define_def(&mut self, def: &raw::DefData, attrs: &Attrs) {
755 let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id }; 755 let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: self.module_id };
756 let ctx = LocationCtx::new(self.def_collector.db, module, self.file_id);
757
758 // FIXME: check attrs to see if this is an attribute macro invocation; 756 // FIXME: check attrs to see if this is an attribute macro invocation;
759 // in which case we don't add the invocation, just a single attribute 757 // in which case we don't add the invocation, just a single attribute
760 // macro invocation 758 // macro invocation
@@ -778,10 +776,15 @@ where
778 PerNs::both(def.into(), def.into()) 776 PerNs::both(def.into(), def.into())
779 } 777 }
780 raw::DefKind::Union(ast_id) => { 778 raw::DefKind::Union(ast_id) => {
781 let id = UnionId::from_ast_id(ctx, ast_id).into(); 779 let def = UnionLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) }
782 PerNs::both(id, id) 780 .intern(self.def_collector.db);
781 PerNs::both(def.into(), def.into())
782 }
783 raw::DefKind::Enum(ast_id) => {
784 let def = EnumLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) }
785 .intern(self.def_collector.db);
786 PerNs::types(def.into())
783 } 787 }
784 raw::DefKind::Enum(ast_id) => PerNs::types(EnumId::from_ast_id(ctx, ast_id).into()),
785 raw::DefKind::Const(ast_id) => { 788 raw::DefKind::Const(ast_id) => {
786 let def = ConstLoc { 789 let def = ConstLoc {
787 container: ContainerId::ModuleId(module), 790 container: ContainerId::ModuleId(module),
diff --git a/crates/ra_hir_def/src/src.rs b/crates/ra_hir_def/src/src.rs
index 7e212adb1..20200d1db 100644
--- a/crates/ra_hir_def/src/src.rs
+++ b/crates/ra_hir_def/src/src.rs
@@ -5,7 +5,8 @@ use ra_arena::map::ArenaMap;
5use ra_syntax::ast; 5use ra_syntax::ast;
6 6
7use crate::{ 7use crate::{
8 db::DefDatabase, ConstLoc, FunctionLoc, ImplLoc, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, 8 db::DefDatabase, ConstLoc, EnumLoc, FunctionLoc, ImplLoc, StaticLoc, StructLoc, TraitLoc,
9 TypeAliasLoc, UnionLoc,
9}; 10};
10 11
11pub trait HasSource { 12pub trait HasSource {
@@ -76,6 +77,24 @@ impl HasSource for StructLoc {
76 } 77 }
77} 78}
78 79
80impl HasSource for UnionLoc {
81 type Value = ast::UnionDef;
82
83 fn source(&self, db: &impl DefDatabase) -> InFile<ast::UnionDef> {
84 let node = self.ast_id.to_node(db);
85 InFile::new(self.ast_id.file_id, node)
86 }
87}
88
89impl HasSource for EnumLoc {
90 type Value = ast::EnumDef;
91
92 fn source(&self, db: &impl DefDatabase) -> InFile<ast::EnumDef> {
93 let node = self.ast_id.to_node(db);
94 InFile::new(self.ast_id.file_id, node)
95 }
96}
97
79pub trait HasChildSource { 98pub trait HasChildSource {
80 type ChildId; 99 type ChildId;
81 type Value; 100 type Value;