aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs32
1 files changed, 12 insertions, 20 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index cb990f4e2..f436d5d5e 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -10,8 +10,9 @@ use hir_def::{
10 adt::VariantData, 10 adt::VariantData,
11 body::scope::ExprScopes, 11 body::scope::ExprScopes,
12 builtin_type::BuiltinType, 12 builtin_type::BuiltinType,
13 traits::TraitData,
13 type_ref::{Mutability, TypeRef}, 14 type_ref::{Mutability, TypeRef},
14 CrateModuleId, ImplId, LocalEnumVariantId, LocalStructFieldId, ModuleId, UnionId, 15 AssocItemId, CrateModuleId, ImplId, LocalEnumVariantId, LocalStructFieldId, ModuleId, UnionId,
15}; 16};
16use hir_expand::{ 17use hir_expand::{
17 diagnostics::DiagnosticSink, 18 diagnostics::DiagnosticSink,
@@ -30,7 +31,6 @@ use crate::{
30 TypeAliasId, 31 TypeAliasId,
31 }, 32 },
32 resolve::{Resolver, Scope, TypeNs}, 33 resolve::{Resolver, Scope, TypeNs},
33 traits::TraitData,
34 ty::{InferenceResult, Namespace, TraitRef}, 34 ty::{InferenceResult, Namespace, TraitRef},
35 Either, HasSource, ImportId, Name, ScopeDef, Source, Ty, 35 Either, HasSource, ImportId, Name, ScopeDef, Source, Ty,
36}; 36};
@@ -230,15 +230,7 @@ impl Module {
230 230
231 pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> { 231 pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> {
232 let def_map = db.crate_def_map(self.id.krate); 232 let def_map = db.crate_def_map(self.id.krate);
233 def_map[self.id.module_id] 233 def_map[self.id.module_id].scope.declarations().map(ModuleDef::from).collect()
234 .scope
235 .entries()
236 .filter_map(|(_name, res)| if res.import.is_none() { Some(res.def) } else { None })
237 .flat_map(|per_ns| {
238 per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter())
239 })
240 .map(ModuleDef::from)
241 .collect()
242 } 234 }
243 235
244 pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> { 236 pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> {
@@ -693,7 +685,7 @@ impl Function {
693 685
694 /// The containing trait, if this is a trait method definition. 686 /// The containing trait, if this is a trait method definition.
695 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> { 687 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
696 db.trait_items_index(self.module(db)).get_parent_trait(self.into()) 688 db.trait_items_index(self.module(db).id).get_parent_trait(self.id.into()).map(Trait::from)
697 } 689 }
698 690
699 pub fn container(self, db: &impl DefDatabase) -> Option<Container> { 691 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
@@ -757,7 +749,7 @@ impl Const {
757 } 749 }
758 750
759 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> { 751 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
760 db.trait_items_index(self.module(db)).get_parent_trait(self.into()) 752 db.trait_items_index(self.module(db).id).get_parent_trait(self.id.into()).map(Trait::from)
761 } 753 }
762 754
763 pub fn container(self, db: &impl DefDatabase) -> Option<Container> { 755 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
@@ -861,11 +853,11 @@ impl Trait {
861 } 853 }
862 854
863 pub fn name(self, db: &impl DefDatabase) -> Option<Name> { 855 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
864 self.trait_data(db).name().clone() 856 self.trait_data(db).name.clone()
865 } 857 }
866 858
867 pub fn items(self, db: &impl DefDatabase) -> Vec<AssocItem> { 859 pub fn items(self, db: &impl DefDatabase) -> Vec<AssocItem> {
868 self.trait_data(db).items().to_vec() 860 self.trait_data(db).items.iter().map(|it| (*it).into()).collect()
869 } 861 }
870 862
871 fn direct_super_traits(self, db: &impl HirDatabase) -> Vec<Trait> { 863 fn direct_super_traits(self, db: &impl HirDatabase) -> Vec<Trait> {
@@ -912,10 +904,10 @@ impl Trait {
912 pub fn associated_type_by_name(self, db: &impl DefDatabase, name: &Name) -> Option<TypeAlias> { 904 pub fn associated_type_by_name(self, db: &impl DefDatabase, name: &Name) -> Option<TypeAlias> {
913 let trait_data = self.trait_data(db); 905 let trait_data = self.trait_data(db);
914 trait_data 906 trait_data
915 .items() 907 .items
916 .iter() 908 .iter()
917 .filter_map(|item| match item { 909 .filter_map(|item| match item {
918 AssocItem::TypeAlias(t) => Some(*t), 910 AssocItemId::TypeAliasId(t) => Some(TypeAlias::from(*t)),
919 _ => None, 911 _ => None,
920 }) 912 })
921 .find(|t| &t.name(db) == name) 913 .find(|t| &t.name(db) == name)
@@ -930,7 +922,7 @@ impl Trait {
930 } 922 }
931 923
932 pub(crate) fn trait_data(self, db: &impl DefDatabase) -> Arc<TraitData> { 924 pub(crate) fn trait_data(self, db: &impl DefDatabase) -> Arc<TraitData> {
933 db.trait_data(self) 925 db.trait_data(self.id)
934 } 926 }
935 927
936 pub fn trait_ref(self, db: &impl HirDatabase) -> TraitRef { 928 pub fn trait_ref(self, db: &impl HirDatabase) -> TraitRef {
@@ -938,7 +930,7 @@ impl Trait {
938 } 930 }
939 931
940 pub fn is_auto(self, db: &impl DefDatabase) -> bool { 932 pub fn is_auto(self, db: &impl DefDatabase) -> bool {
941 self.trait_data(db).is_auto() 933 self.trait_data(db).auto
942 } 934 }
943 935
944 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver { 936 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver {
@@ -971,7 +963,7 @@ impl TypeAlias {
971 963
972 /// The containing trait, if this is a trait method definition. 964 /// The containing trait, if this is a trait method definition.
973 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> { 965 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
974 db.trait_items_index(self.module(db)).get_parent_trait(self.into()) 966 db.trait_items_index(self.module(db).id).get_parent_trait(self.id.into()).map(Trait::from)
975 } 967 }
976 968
977 pub fn container(self, db: &impl DefDatabase) -> Option<Container> { 969 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {