aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r--crates/ra_hir_def/src/lib.rs57
1 files changed, 37 insertions, 20 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 8e8c2d749..bc5530896 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -27,7 +27,7 @@ pub mod body;
27pub mod resolver; 27pub mod resolver;
28 28
29mod trace; 29mod trace;
30mod nameres; 30pub mod nameres;
31 31
32#[cfg(test)] 32#[cfg(test)]
33mod test_db; 33mod test_db;
@@ -50,7 +50,7 @@ impl_arena_id!(LocalImportId);
50#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 50#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
51pub struct ModuleId { 51pub struct ModuleId {
52 pub krate: CrateId, 52 pub krate: CrateId,
53 pub module_id: LocalModuleId, 53 pub local_id: LocalModuleId,
54} 54}
55 55
56/// An ID of a module, **local** to a specific crate 56/// An ID of a module, **local** to a specific crate
@@ -141,30 +141,26 @@ impl Lookup for FunctionId {
141} 141}
142 142
143#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 143#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
144pub struct StructOrUnionId(salsa::InternId); 144pub struct StructId(salsa::InternId);
145impl_intern_key!(StructOrUnionId); 145impl_intern_key!(StructId);
146impl AstItemDef<ast::StructDef> for StructOrUnionId { 146impl AstItemDef<ast::StructDef> for StructId {
147 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StructDef>) -> Self { 147 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StructDef>) -> Self {
148 db.intern_struct_or_union(loc) 148 db.intern_struct(loc)
149 } 149 }
150 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StructDef> { 150 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StructDef> {
151 db.lookup_intern_struct_or_union(self) 151 db.lookup_intern_struct(self)
152 } 152 }
153} 153}
154 154
155#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 155#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
156pub struct StructId(pub StructOrUnionId); 156pub struct UnionId(salsa::InternId);
157impl From<StructId> for StructOrUnionId { 157impl_intern_key!(UnionId);
158 fn from(id: StructId) -> StructOrUnionId { 158impl AstItemDef<ast::UnionDef> for UnionId {
159 id.0 159 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::UnionDef>) -> Self {
160 db.intern_union(loc)
160 } 161 }
161} 162 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::UnionDef> {
162 163 db.lookup_intern_union(self)
163#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
164pub struct UnionId(pub StructOrUnionId);
165impl From<UnionId> for StructOrUnionId {
166 fn from(id: UnionId) -> StructOrUnionId {
167 id.0
168 } 164 }
169} 165}
170 166
@@ -402,6 +398,16 @@ impl_froms!(
402 ConstId 398 ConstId
403); 399);
404 400
401impl From<AssocItemId> for GenericDefId {
402 fn from(item: AssocItemId) -> Self {
403 match item {
404 AssocItemId::FunctionId(f) => f.into(),
405 AssocItemId::ConstId(c) => c.into(),
406 AssocItemId::TypeAliasId(t) => t.into(),
407 }
408 }
409}
410
405#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 411#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
406pub enum AttrDefId { 412pub enum AttrDefId {
407 ModuleId(ModuleId), 413 ModuleId(ModuleId),
@@ -435,6 +441,7 @@ impl_froms!(
435pub enum VariantId { 441pub enum VariantId {
436 EnumVariantId(EnumVariantId), 442 EnumVariantId(EnumVariantId),
437 StructId(StructId), 443 StructId(StructId),
444 UnionId(UnionId),
438} 445}
439impl_froms!(VariantId: EnumVariantId, StructId); 446impl_froms!(VariantId: EnumVariantId, StructId);
440 447
@@ -485,13 +492,23 @@ impl HasModule for ConstLoc {
485impl HasModule for AdtId { 492impl HasModule for AdtId {
486 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 493 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
487 match self { 494 match self {
488 AdtId::StructId(it) => it.0.module(db), 495 AdtId::StructId(it) => it.module(db),
489 AdtId::UnionId(it) => it.0.module(db), 496 AdtId::UnionId(it) => it.module(db),
490 AdtId::EnumId(it) => it.module(db), 497 AdtId::EnumId(it) => it.module(db),
491 } 498 }
492 } 499 }
493} 500}
494 501
502impl HasModule for DefWithBodyId {
503 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
504 match self {
505 DefWithBodyId::FunctionId(it) => it.lookup(db).module(db),
506 DefWithBodyId::StaticId(it) => it.lookup(db).module(db),
507 DefWithBodyId::ConstId(it) => it.lookup(db).module(db),
508 }
509 }
510}
511
495impl HasModule for StaticLoc { 512impl HasModule for StaticLoc {
496 fn module(&self, _db: &impl db::DefDatabase) -> ModuleId { 513 fn module(&self, _db: &impl db::DefDatabase) -> ModuleId {
497 self.container 514 self.container