diff options
author | Seivan Heidari <[email protected]> | 2019-11-28 07:19:14 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-11-28 07:19:14 +0000 |
commit | 18a0937585b836ec5ed054b9ae48e0156ab6d9ef (patch) | |
tree | 9de2c0267ddcc00df717f90034d0843d751a851b /crates/ra_hir_def/src/lib.rs | |
parent | a7394b44c870f585eacfeb3036a33471aff49ff8 (diff) | |
parent | 484acc8a61d599662ed63a4cbda091d38a982551 (diff) |
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into feature/themes
Diffstat (limited to 'crates/ra_hir_def/src/lib.rs')
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 57 |
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; | |||
27 | pub mod resolver; | 27 | pub mod resolver; |
28 | 28 | ||
29 | mod trace; | 29 | mod trace; |
30 | mod nameres; | 30 | pub mod nameres; |
31 | 31 | ||
32 | #[cfg(test)] | 32 | #[cfg(test)] |
33 | mod test_db; | 33 | mod 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)] |
51 | pub struct ModuleId { | 51 | pub 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)] |
144 | pub struct StructOrUnionId(salsa::InternId); | 144 | pub struct StructId(salsa::InternId); |
145 | impl_intern_key!(StructOrUnionId); | 145 | impl_intern_key!(StructId); |
146 | impl AstItemDef<ast::StructDef> for StructOrUnionId { | 146 | impl 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)] |
156 | pub struct StructId(pub StructOrUnionId); | 156 | pub struct UnionId(salsa::InternId); |
157 | impl From<StructId> for StructOrUnionId { | 157 | impl_intern_key!(UnionId); |
158 | fn from(id: StructId) -> StructOrUnionId { | 158 | impl 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)] | ||
164 | pub struct UnionId(pub StructOrUnionId); | ||
165 | impl 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 | ||
401 | impl 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)] |
406 | pub enum AttrDefId { | 412 | pub enum AttrDefId { |
407 | ModuleId(ModuleId), | 413 | ModuleId(ModuleId), |
@@ -435,6 +441,7 @@ impl_froms!( | |||
435 | pub enum VariantId { | 441 | pub enum VariantId { |
436 | EnumVariantId(EnumVariantId), | 442 | EnumVariantId(EnumVariantId), |
437 | StructId(StructId), | 443 | StructId(StructId), |
444 | UnionId(UnionId), | ||
438 | } | 445 | } |
439 | impl_froms!(VariantId: EnumVariantId, StructId); | 446 | impl_froms!(VariantId: EnumVariantId, StructId); |
440 | 447 | ||
@@ -485,13 +492,23 @@ impl HasModule for ConstLoc { | |||
485 | impl HasModule for AdtId { | 492 | impl 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 | ||
502 | impl 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 | |||
495 | impl HasModule for StaticLoc { | 512 | impl 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 |