From 06fa3d8389c833b01f482bf35b0f850e627612b9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Nov 2019 14:22:06 +0300 Subject: Move traits to hir_def --- crates/ra_hir/src/code_model.rs | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'crates/ra_hir/src/code_model.rs') 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::{ adt::VariantData, body::scope::ExprScopes, builtin_type::BuiltinType, + traits::TraitData, type_ref::{Mutability, TypeRef}, - CrateModuleId, ImplId, LocalEnumVariantId, LocalStructFieldId, ModuleId, UnionId, + AssocItemId, CrateModuleId, ImplId, LocalEnumVariantId, LocalStructFieldId, ModuleId, UnionId, }; use hir_expand::{ diagnostics::DiagnosticSink, @@ -30,7 +31,6 @@ use crate::{ TypeAliasId, }, resolve::{Resolver, Scope, TypeNs}, - traits::TraitData, ty::{InferenceResult, Namespace, TraitRef}, Either, HasSource, ImportId, Name, ScopeDef, Source, Ty, }; @@ -230,15 +230,7 @@ impl Module { pub fn declarations(self, db: &impl DefDatabase) -> Vec { let def_map = db.crate_def_map(self.id.krate); - def_map[self.id.module_id] - .scope - .entries() - .filter_map(|(_name, res)| if res.import.is_none() { Some(res.def) } else { None }) - .flat_map(|per_ns| { - per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter()) - }) - .map(ModuleDef::from) - .collect() + def_map[self.id.module_id].scope.declarations().map(ModuleDef::from).collect() } pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec { @@ -693,7 +685,7 @@ impl Function { /// The containing trait, if this is a trait method definition. pub fn parent_trait(self, db: &impl DefDatabase) -> Option { - db.trait_items_index(self.module(db)).get_parent_trait(self.into()) + db.trait_items_index(self.module(db).id).get_parent_trait(self.id.into()).map(Trait::from) } pub fn container(self, db: &impl DefDatabase) -> Option { @@ -757,7 +749,7 @@ impl Const { } pub fn parent_trait(self, db: &impl DefDatabase) -> Option { - db.trait_items_index(self.module(db)).get_parent_trait(self.into()) + db.trait_items_index(self.module(db).id).get_parent_trait(self.id.into()).map(Trait::from) } pub fn container(self, db: &impl DefDatabase) -> Option { @@ -861,11 +853,11 @@ impl Trait { } pub fn name(self, db: &impl DefDatabase) -> Option { - self.trait_data(db).name().clone() + self.trait_data(db).name.clone() } pub fn items(self, db: &impl DefDatabase) -> Vec { - self.trait_data(db).items().to_vec() + self.trait_data(db).items.iter().map(|it| (*it).into()).collect() } fn direct_super_traits(self, db: &impl HirDatabase) -> Vec { @@ -912,10 +904,10 @@ impl Trait { pub fn associated_type_by_name(self, db: &impl DefDatabase, name: &Name) -> Option { let trait_data = self.trait_data(db); trait_data - .items() + .items .iter() .filter_map(|item| match item { - AssocItem::TypeAlias(t) => Some(*t), + AssocItemId::TypeAliasId(t) => Some(TypeAlias::from(*t)), _ => None, }) .find(|t| &t.name(db) == name) @@ -930,7 +922,7 @@ impl Trait { } pub(crate) fn trait_data(self, db: &impl DefDatabase) -> Arc { - db.trait_data(self) + db.trait_data(self.id) } pub fn trait_ref(self, db: &impl HirDatabase) -> TraitRef { @@ -938,7 +930,7 @@ impl Trait { } pub fn is_auto(self, db: &impl DefDatabase) -> bool { - self.trait_data(db).is_auto() + self.trait_data(db).auto } pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver { @@ -971,7 +963,7 @@ impl TypeAlias { /// The containing trait, if this is a trait method definition. pub fn parent_trait(self, db: &impl DefDatabase) -> Option { - db.trait_items_index(self.module(db)).get_parent_trait(self.into()) + db.trait_items_index(self.module(db).id).get_parent_trait(self.id.into()).map(Trait::from) } pub fn container(self, db: &impl DefDatabase) -> Option { -- cgit v1.2.3