aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir_def/src/body/lower.rs4
-rw-r--r--crates/ra_hir_def/src/lib.rs22
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs9
-rw-r--r--crates/ra_hir_def/src/resolver.rs18
-rw-r--r--crates/ra_hir_ty/src/infer/path.rs2
-rw-r--r--crates/ra_hir_ty/src/method_resolution.rs2
-rw-r--r--crates/ra_hir_ty/src/utils.rs2
7 files changed, 41 insertions, 18 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index afd5231cc..0103a1aab 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -25,7 +25,7 @@ use crate::{
25 path::GenericArgs, 25 path::GenericArgs,
26 path::Path, 26 path::Path,
27 type_ref::{Mutability, TypeRef}, 27 type_ref::{Mutability, TypeRef},
28 AssocContainerId, DefWithBodyId, FunctionLoc, Intern, 28 ContainerId, DefWithBodyId, FunctionLoc, Intern,
29}; 29};
30 30
31pub(super) fn lower( 31pub(super) fn lower(
@@ -490,7 +490,7 @@ where
490 } 490 }
491 491
492 fn collect_block_items(&mut self, block: &ast::Block) { 492 fn collect_block_items(&mut self, block: &ast::Block) {
493 let container = AssocContainerId::DefWithBodyId(self.def); 493 let container = ContainerId::DefWithBodyId(self.def).into();
494 for item in block.items() { 494 for item in block.items() {
495 match item { 495 match item {
496 ast::ModuleItem::FnDef(def) => { 496 ast::ModuleItem::FnDef(def) => {
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 3d42762ae..5e46db1aa 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -331,12 +331,18 @@ pub struct LocalTypeParamId(RawId);
331impl_arena_id!(LocalTypeParamId); 331impl_arena_id!(LocalTypeParamId);
332 332
333#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 333#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
334pub enum AssocContainerId { 334pub enum ContainerId {
335 ModuleId(ModuleId), 335 ModuleId(ModuleId),
336 DefWithBodyId(DefWithBodyId),
337}
338
339#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
340pub enum AssocContainerId {
341 ContainerId(ContainerId),
336 ImplId(ImplId), 342 ImplId(ImplId),
337 TraitId(TraitId), 343 TraitId(TraitId),
338 DefWithBodyId(DefWithBodyId),
339} 344}
345impl_froms!(AssocContainerId: ContainerId);
340 346
341/// A Data Type 347/// A Data Type
342#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 348#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -479,13 +485,21 @@ pub trait HasModule {
479 fn module(&self, db: &impl db::DefDatabase) -> ModuleId; 485 fn module(&self, db: &impl db::DefDatabase) -> ModuleId;
480} 486}
481 487
488impl HasModule for ContainerId {
489 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
490 match *self {
491 ContainerId::ModuleId(it) => it,
492 ContainerId::DefWithBodyId(it) => it.module(db),
493 }
494 }
495}
496
482impl HasModule for AssocContainerId { 497impl HasModule for AssocContainerId {
483 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 498 fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
484 match *self { 499 match *self {
485 AssocContainerId::ModuleId(it) => it, 500 AssocContainerId::ContainerId(it) => it.module(db),
486 AssocContainerId::ImplId(it) => it.lookup(db).container, 501 AssocContainerId::ImplId(it) => it.lookup(db).container,
487 AssocContainerId::TraitId(it) => it.lookup(db).container, 502 AssocContainerId::TraitId(it) => it.lookup(db).container,
488 AssocContainerId::DefWithBodyId(it) => it.module(db),
489 } 503 }
490 } 504 }
491} 505}
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index 848959f7c..0f3319f30 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::{ModPath, PathKind}, 25 path::{ModPath, PathKind},
26 per_ns::PerNs, 26 per_ns::PerNs,
27 AdtId, AssocContainerId, AstId, ConstLoc, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern, 27 AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
28 LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc, 28 LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc,
29 TypeAliasLoc, UnionLoc, 29 TypeAliasLoc, UnionLoc,
30}; 30};
@@ -760,10 +760,11 @@ where
760 self.collect_derives(attrs, def); 760 self.collect_derives(attrs, def);
761 761
762 let name = def.name.clone(); 762 let name = def.name.clone();
763 let container = ContainerId::ModuleId(module);
763 let def: PerNs = match def.kind { 764 let def: PerNs = match def.kind {
764 raw::DefKind::Function(ast_id) => { 765 raw::DefKind::Function(ast_id) => {
765 let def = FunctionLoc { 766 let def = FunctionLoc {
766 container: AssocContainerId::ModuleId(module), 767 container: container.into(),
767 ast_id: AstId::new(self.file_id, ast_id), 768 ast_id: AstId::new(self.file_id, ast_id),
768 } 769 }
769 .intern(self.def_collector.db); 770 .intern(self.def_collector.db);
@@ -787,7 +788,7 @@ where
787 } 788 }
788 raw::DefKind::Const(ast_id) => { 789 raw::DefKind::Const(ast_id) => {
789 let def = ConstLoc { 790 let def = ConstLoc {
790 container: AssocContainerId::ModuleId(module), 791 container: container.into(),
791 ast_id: AstId::new(self.file_id, ast_id), 792 ast_id: AstId::new(self.file_id, ast_id),
792 } 793 }
793 .intern(self.def_collector.db); 794 .intern(self.def_collector.db);
@@ -808,7 +809,7 @@ where
808 } 809 }
809 raw::DefKind::TypeAlias(ast_id) => { 810 raw::DefKind::TypeAlias(ast_id) => {
810 let def = TypeAliasLoc { 811 let def = TypeAliasLoc {
811 container: AssocContainerId::ModuleId(module), 812 container: container.into(),
812 ast_id: AstId::new(self.file_id, ast_id), 813 ast_id: AstId::new(self.file_id, ast_id),
813 } 814 }
814 .intern(self.def_collector.db); 815 .intern(self.def_collector.db);
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index d79c9813b..af9d194f8 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -17,9 +17,9 @@ use crate::{
17 nameres::{BuiltinShadowMode, CrateDefMap}, 17 nameres::{BuiltinShadowMode, CrateDefMap},
18 path::{ModPath, PathKind}, 18 path::{ModPath, PathKind},
19 per_ns::PerNs, 19 per_ns::PerNs,
20 AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, 20 AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId,
21 GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId, 21 FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId,
22 StructId, TraitId, TypeAliasId, TypeParamId, VariantId, 22 StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId,
23}; 23};
24 24
25#[derive(Debug, Clone, Default)] 25#[derive(Debug, Clone, Default)]
@@ -580,13 +580,21 @@ impl HasResolver for DefWithBodyId {
580 } 580 }
581} 581}
582 582
583impl HasResolver for ContainerId {
584 fn resolver(self, db: &impl DefDatabase) -> Resolver {
585 match self {
586 ContainerId::ModuleId(it) => it.resolver(db),
587 ContainerId::DefWithBodyId(it) => it.resolver(db),
588 }
589 }
590}
591
583impl HasResolver for AssocContainerId { 592impl HasResolver for AssocContainerId {
584 fn resolver(self, db: &impl DefDatabase) -> Resolver { 593 fn resolver(self, db: &impl DefDatabase) -> Resolver {
585 match self { 594 match self {
595 AssocContainerId::ContainerId(it) => it.resolver(db),
586 AssocContainerId::TraitId(it) => it.resolver(db), 596 AssocContainerId::TraitId(it) => it.resolver(db),
587 AssocContainerId::ImplId(it) => it.resolver(db), 597 AssocContainerId::ImplId(it) => it.resolver(db),
588 AssocContainerId::ModuleId(it) => it.resolver(db),
589 AssocContainerId::DefWithBodyId(it) => it.resolver(db),
590 } 598 }
591 } 599 }
592} 600}
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs
index a96ab75d1..ffd358367 100644
--- a/crates/ra_hir_ty/src/infer/path.rs
+++ b/crates/ra_hir_ty/src/infer/path.rs
@@ -237,7 +237,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
237 })); 237 }));
238 Some(substs) 238 Some(substs)
239 } 239 }
240 AssocContainerId::ModuleId(_) | AssocContainerId::DefWithBodyId(_) => None, 240 AssocContainerId::ContainerId(_) => None,
241 }; 241 };
242 242
243 self.write_assoc_resolution(id, item.into()); 243 self.write_assoc_resolution(id, item.into());
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs
index 1c2e7b934..1b2f4014c 100644
--- a/crates/ra_hir_ty/src/method_resolution.rs
+++ b/crates/ra_hir_ty/src/method_resolution.rs
@@ -456,7 +456,7 @@ fn transform_receiver_ty(
456 .fill_with_unknown() 456 .fill_with_unknown()
457 .build(), 457 .build(),
458 AssocContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?, 458 AssocContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?,
459 AssocContainerId::ModuleId(_) | AssocContainerId::DefWithBodyId(_) => unreachable!(), 459 AssocContainerId::ContainerId(_) => unreachable!(),
460 }; 460 };
461 let sig = db.callable_item_signature(function_id.into()); 461 let sig = db.callable_item_signature(function_id.into());
462 Some(sig.params()[0].clone().subst(&substs)) 462 Some(sig.params()[0].clone().subst(&substs))
diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs
index 8b5b611ec..0b1806a84 100644
--- a/crates/ra_hir_ty/src/utils.rs
+++ b/crates/ra_hir_ty/src/utils.rs
@@ -157,6 +157,6 @@ fn parent_generic_def(db: &impl DefDatabase, def: GenericDefId) -> Option<Generi
157 match container { 157 match container {
158 AssocContainerId::ImplId(it) => Some(it.into()), 158 AssocContainerId::ImplId(it) => Some(it.into()),
159 AssocContainerId::TraitId(it) => Some(it.into()), 159 AssocContainerId::TraitId(it) => Some(it.into()),
160 AssocContainerId::ModuleId(_) | AssocContainerId::DefWithBodyId(_) => None, 160 AssocContainerId::ContainerId(_) => None,
161 } 161 }
162} 162}