aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs53
-rw-r--r--crates/ra_hir/src/code_model/src.rs3
-rw-r--r--crates/ra_hir/src/db.rs10
-rw-r--r--crates/ra_hir/src/from_source.rs65
-rw-r--r--crates/ra_hir/src/lib.rs1
-rw-r--r--crates/ra_hir/src/source_binder.rs15
-rw-r--r--crates/ra_hir/src/traits.rs82
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs6
8 files changed, 101 insertions, 134 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index cb990f4e2..c49190a0f 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -10,8 +10,10 @@ 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, FunctionContainerId, HasModule, ImplId, LocalEnumVariantId,
16 LocalStructFieldId, Lookup, ModuleId, UnionId,
15}; 17};
16use hir_expand::{ 18use hir_expand::{
17 diagnostics::DiagnosticSink, 19 diagnostics::DiagnosticSink,
@@ -30,7 +32,6 @@ use crate::{
30 TypeAliasId, 32 TypeAliasId,
31 }, 33 },
32 resolve::{Resolver, Scope, TypeNs}, 34 resolve::{Resolver, Scope, TypeNs},
33 traits::TraitData,
34 ty::{InferenceResult, Namespace, TraitRef}, 35 ty::{InferenceResult, Namespace, TraitRef},
35 Either, HasSource, ImportId, Name, ScopeDef, Source, Ty, 36 Either, HasSource, ImportId, Name, ScopeDef, Source, Ty,
36}; 37};
@@ -230,15 +231,7 @@ impl Module {
230 231
231 pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> { 232 pub fn declarations(self, db: &impl DefDatabase) -> Vec<ModuleDef> {
232 let def_map = db.crate_def_map(self.id.krate); 233 let def_map = db.crate_def_map(self.id.krate);
233 def_map[self.id.module_id] 234 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 } 235 }
243 236
244 pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> { 237 pub fn impl_blocks(self, db: &impl DefDatabase) -> Vec<ImplBlock> {
@@ -655,7 +648,7 @@ impl FnData {
655 648
656impl Function { 649impl Function {
657 pub fn module(self, db: &impl DefDatabase) -> Module { 650 pub fn module(self, db: &impl DefDatabase) -> Module {
658 Module { id: self.id.module(db) } 651 self.id.lookup(db).module(db).into()
659 } 652 }
660 653
661 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 654 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
@@ -688,21 +681,25 @@ impl Function {
688 681
689 /// The containing impl block, if this is a method. 682 /// The containing impl block, if this is a method.
690 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> { 683 pub fn impl_block(self, db: &impl DefDatabase) -> Option<ImplBlock> {
691 ImplBlock::containing(db, self.into()) 684 match self.container(db) {
685 Some(Container::ImplBlock(it)) => Some(it),
686 _ => None,
687 }
692 } 688 }
693 689
694 /// The containing trait, if this is a trait method definition. 690 /// The containing trait, if this is a trait method definition.
695 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> { 691 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
696 db.trait_items_index(self.module(db)).get_parent_trait(self.into()) 692 match self.container(db) {
693 Some(Container::Trait(it)) => Some(it),
694 _ => None,
695 }
697 } 696 }
698 697
699 pub fn container(self, db: &impl DefDatabase) -> Option<Container> { 698 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
700 if let Some(impl_block) = self.impl_block(db) { 699 match self.id.lookup(db).container {
701 Some(impl_block.into()) 700 FunctionContainerId::TraitId(it) => Some(Container::Trait(it.into())),
702 } else if let Some(trait_) = self.parent_trait(db) { 701 FunctionContainerId::ImplId(it) => Some(Container::ImplBlock(it.into())),
703 Some(trait_.into()) 702 FunctionContainerId::ModuleId(_) => None,
704 } else {
705 None
706 } 703 }
707 } 704 }
708 705
@@ -757,7 +754,7 @@ impl Const {
757 } 754 }
758 755
759 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> { 756 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
760 db.trait_items_index(self.module(db)).get_parent_trait(self.into()) 757 db.trait_items_index(self.module(db).id).get_parent_trait(self.id.into()).map(Trait::from)
761 } 758 }
762 759
763 pub fn container(self, db: &impl DefDatabase) -> Option<Container> { 760 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
@@ -861,11 +858,11 @@ impl Trait {
861 } 858 }
862 859
863 pub fn name(self, db: &impl DefDatabase) -> Option<Name> { 860 pub fn name(self, db: &impl DefDatabase) -> Option<Name> {
864 self.trait_data(db).name().clone() 861 self.trait_data(db).name.clone()
865 } 862 }
866 863
867 pub fn items(self, db: &impl DefDatabase) -> Vec<AssocItem> { 864 pub fn items(self, db: &impl DefDatabase) -> Vec<AssocItem> {
868 self.trait_data(db).items().to_vec() 865 self.trait_data(db).items.iter().map(|it| (*it).into()).collect()
869 } 866 }
870 867
871 fn direct_super_traits(self, db: &impl HirDatabase) -> Vec<Trait> { 868 fn direct_super_traits(self, db: &impl HirDatabase) -> Vec<Trait> {
@@ -912,10 +909,10 @@ impl Trait {
912 pub fn associated_type_by_name(self, db: &impl DefDatabase, name: &Name) -> Option<TypeAlias> { 909 pub fn associated_type_by_name(self, db: &impl DefDatabase, name: &Name) -> Option<TypeAlias> {
913 let trait_data = self.trait_data(db); 910 let trait_data = self.trait_data(db);
914 trait_data 911 trait_data
915 .items() 912 .items
916 .iter() 913 .iter()
917 .filter_map(|item| match item { 914 .filter_map(|item| match item {
918 AssocItem::TypeAlias(t) => Some(*t), 915 AssocItemId::TypeAliasId(t) => Some(TypeAlias::from(*t)),
919 _ => None, 916 _ => None,
920 }) 917 })
921 .find(|t| &t.name(db) == name) 918 .find(|t| &t.name(db) == name)
@@ -930,7 +927,7 @@ impl Trait {
930 } 927 }
931 928
932 pub(crate) fn trait_data(self, db: &impl DefDatabase) -> Arc<TraitData> { 929 pub(crate) fn trait_data(self, db: &impl DefDatabase) -> Arc<TraitData> {
933 db.trait_data(self) 930 db.trait_data(self.id)
934 } 931 }
935 932
936 pub fn trait_ref(self, db: &impl HirDatabase) -> TraitRef { 933 pub fn trait_ref(self, db: &impl HirDatabase) -> TraitRef {
@@ -938,7 +935,7 @@ impl Trait {
938 } 935 }
939 936
940 pub fn is_auto(self, db: &impl DefDatabase) -> bool { 937 pub fn is_auto(self, db: &impl DefDatabase) -> bool {
941 self.trait_data(db).is_auto() 938 self.trait_data(db).auto
942 } 939 }
943 940
944 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver { 941 pub(crate) fn resolver(self, db: &impl DefDatabase) -> Resolver {
@@ -971,7 +968,7 @@ impl TypeAlias {
971 968
972 /// The containing trait, if this is a trait method definition. 969 /// The containing trait, if this is a trait method definition.
973 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> { 970 pub fn parent_trait(self, db: &impl DefDatabase) -> Option<Trait> {
974 db.trait_items_index(self.module(db)).get_parent_trait(self.into()) 971 db.trait_items_index(self.module(db).id).get_parent_trait(self.id.into()).map(Trait::from)
975 } 972 }
976 973
977 pub fn container(self, db: &impl DefDatabase) -> Option<Container> { 974 pub fn container(self, db: &impl DefDatabase) -> Option<Container> {
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index 556417b0f..91cab7414 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -1,5 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir_def::{HasSource as _, Lookup};
3use ra_syntax::ast::{self, AstNode}; 4use ra_syntax::ast::{self, AstNode};
4 5
5use crate::{ 6use crate::{
@@ -113,7 +114,7 @@ impl HasSource for EnumVariant {
113impl HasSource for Function { 114impl HasSource for Function {
114 type Ast = ast::FnDef; 115 type Ast = ast::FnDef;
115 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::FnDef> { 116 fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<ast::FnDef> {
116 self.id.source(db) 117 self.id.lookup(db).source(db)
117 } 118 }
118} 119}
119impl HasSource for Const { 120impl HasSource for Const {
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 0d35014a0..73859e1e9 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -11,7 +11,6 @@ use crate::{
11 generics::{GenericDef, GenericParams}, 11 generics::{GenericDef, GenericParams},
12 ids, 12 ids,
13 lang_item::{LangItemTarget, LangItems}, 13 lang_item::{LangItemTarget, LangItems},
14 traits::TraitData,
15 ty::{ 14 ty::{
16 method_resolution::CrateImplBlocks, 15 method_resolution::CrateImplBlocks,
17 traits::{AssocTyValue, Impl}, 16 traits::{AssocTyValue, Impl},
@@ -26,7 +25,8 @@ use crate::{
26pub use hir_def::db::{ 25pub use hir_def::db::{
27 BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage, 26 BodyQuery, BodyWithSourceMapQuery, CrateDefMapQuery, DefDatabase2, DefDatabase2Storage,
28 EnumDataQuery, ExprScopesQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, 27 EnumDataQuery, ExprScopesQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage,
29 RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery, 28 RawItemsQuery, RawItemsWithSourceMapQuery, StructDataQuery, TraitDataQuery,
29 TraitItemsIndexQuery,
30}; 30};
31pub use hir_expand::db::{ 31pub use hir_expand::db::{
32 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, 32 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
@@ -37,12 +37,6 @@ pub use hir_expand::db::{
37#[salsa::query_group(DefDatabaseStorage)] 37#[salsa::query_group(DefDatabaseStorage)]
38#[salsa::requires(AstDatabase)] 38#[salsa::requires(AstDatabase)]
39pub trait DefDatabase: HirDebugDatabase + DefDatabase2 { 39pub trait DefDatabase: HirDebugDatabase + DefDatabase2 {
40 #[salsa::invoke(crate::traits::TraitData::trait_data_query)]
41 fn trait_data(&self, t: Trait) -> Arc<TraitData>;
42
43 #[salsa::invoke(crate::traits::TraitItemsIndex::trait_items_index)]
44 fn trait_items_index(&self, module: Module) -> crate::traits::TraitItemsIndex;
45
46 #[salsa::invoke(crate::generics::generic_params_query)] 40 #[salsa::invoke(crate::generics::generic_params_query)]
47 fn generic_params(&self, def: GenericDef) -> Arc<GenericParams>; 41 fn generic_params(&self, def: GenericDef) -> Arc<GenericParams>;
48 42
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index f4dca25cb..303d5f138 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -4,15 +4,15 @@ use hir_def::{ModuleId, StructId, StructOrUnionId, UnionId};
4use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; 4use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind};
5use ra_syntax::{ 5use ra_syntax::{
6 ast::{self, AstNode, NameOwner}, 6 ast::{self, AstNode, NameOwner},
7 match_ast, 7 match_ast, AstPtr,
8}; 8};
9 9
10use crate::{ 10use crate::{
11 db::{AstDatabase, DefDatabase, HirDatabase}, 11 db::{AstDatabase, DefDatabase, HirDatabase},
12 ids::{AstItemDef, LocationCtx}, 12 ids::{AstItemDef, LocationCtx},
13 Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, HasBody, HasSource, ImplBlock, 13 AssocItem, Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, HasBody, HasSource,
14 Local, MacroDef, Module, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, 14 ImplBlock, Local, MacroDef, Module, ModuleDef, ModuleSource, Source, Static, Struct,
15 Union, VariantDef, 15 StructField, Trait, TypeAlias, Union, VariantDef,
16}; 16};
17 17
18pub trait FromSource: Sized { 18pub trait FromSource: Sized {
@@ -52,10 +52,51 @@ impl FromSource for Trait {
52impl FromSource for Function { 52impl FromSource for Function {
53 type Ast = ast::FnDef; 53 type Ast = ast::FnDef;
54 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 54 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
55 let id = from_source(db, src)?; 55 // FIXME: this doesn't try to handle nested declarations
56 Some(Function { id }) 56 for container in src.value.syntax().ancestors() {
57 let res = match_ast! {
58 match container {
59 ast::TraitDef(it) => {
60 let c = Trait::from_source(db, src.with_value(it))?;
61 c.items(db)
62 .into_iter()
63 .filter_map(|it| match it {
64 AssocItem::Function(it) => Some(it),
65 _ => None
66 })
67 .find(|it| same_source(&it.source(db), &src))?
68 },
69 ast::ImplBlock(it) => {
70 let c = ImplBlock::from_source(db, src.with_value(it))?;
71 c.items(db)
72 .into_iter()
73 .filter_map(|it| match it {
74 AssocItem::Function(it) => Some(it),
75 _ => None
76 })
77 .find(|it| same_source(&it.source(db), &src))?
78
79 },
80 _ => { continue },
81 }
82 };
83 return Some(res);
84 }
85
86 let module_source = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
87 let c = Module::from_definition(db, src.with_value(module_source))?;
88 let res = c
89 .declarations(db)
90 .into_iter()
91 .filter_map(|it| match it {
92 ModuleDef::Function(it) => Some(it),
93 _ => None,
94 })
95 .find(|it| same_source(&it.source(db), &src));
96 res
57 } 97 }
58} 98}
99
59impl FromSource for Const { 100impl FromSource for Const {
60 type Ast = ast::ConstDef; 101 type Ast = ast::ConstDef;
61 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 102 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
@@ -108,7 +149,7 @@ impl FromSource for EnumVariant {
108 let parent_enum = src.value.parent_enum(); 149 let parent_enum = src.value.parent_enum();
109 let src_enum = Source { file_id: src.file_id, value: parent_enum }; 150 let src_enum = Source { file_id: src.file_id, value: parent_enum };
110 let variants = Enum::from_source(db, src_enum)?.variants(db); 151 let variants = Enum::from_source(db, src_enum)?.variants(db);
111 variants.into_iter().find(|v| v.source(db) == src) 152 variants.into_iter().find(|v| same_source(&v.source(db), &src))
112 } 153 }
113} 154}
114 155
@@ -216,3 +257,13 @@ where
216 let ctx = LocationCtx::new(db, module.id, src.file_id); 257 let ctx = LocationCtx::new(db, module.id, src.file_id);
217 Some(DEF::from_ast(ctx, &src.value)) 258 Some(DEF::from_ast(ctx, &src.value))
218} 259}
260
261/// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are
262/// equal if they point to exactly the same object.
263///
264/// In general, we do not guarantee that we have exactly one instance of a
265/// syntax tree for each file. We probably should add such guanratree, but, for
266/// the time being, we will use identity-less AstPtr comparison.
267fn same_source<N: AstNode>(s1: &Source<N>, s2: &Source<N>) -> bool {
268 s1.as_ref().map(AstPtr::new) == s2.as_ref().map(AstPtr::new)
269}
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index da33c9591..7ac9a9041 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -33,7 +33,6 @@ pub mod source_binder;
33 33
34mod ids; 34mod ids;
35mod adt; 35mod adt;
36mod traits;
37mod type_alias; 36mod type_alias;
38mod ty; 37mod ty;
39mod impl_block; 38mod impl_block;
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index a1c1daacd..caa8d0082 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -70,7 +70,7 @@ fn def_with_body_from_child_node(
70 child.value.ancestors().find_map(|node| { 70 child.value.ancestors().find_map(|node| {
71 match_ast! { 71 match_ast! {
72 match node { 72 match node {
73 ast::FnDef(def) => { Some(Function {id: ctx.to_def(&def) }.into()) }, 73 ast::FnDef(def) => { return Function::from_source(db, child.with_value(def)).map(DefWithBody::from); },
74 ast::ConstDef(def) => { Some(Const { id: ctx.to_def(&def) }.into()) }, 74 ast::ConstDef(def) => { Some(Const { id: ctx.to_def(&def) }.into()) },
75 ast::StaticDef(def) => { Some(Static { id: ctx.to_def(&def) }.into()) }, 75 ast::StaticDef(def) => { Some(Static { id: ctx.to_def(&def) }.into()) },
76 _ => { None }, 76 _ => { None },
@@ -405,9 +405,16 @@ impl SourceAnalyzer {
405 implements_trait(&canonical_ty, db, &self.resolver, krate, std_future_trait) 405 implements_trait(&canonical_ty, db, &self.resolver, krate, std_future_trait)
406 } 406 }
407 407
408 pub fn expand(&self, db: &impl HirDatabase, macro_call: &ast::MacroCall) -> Option<Expansion> { 408 pub fn expand(
409 let def = self.resolve_macro_call(db, macro_call)?.id; 409 &self,
410 let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(macro_call)); 410 db: &impl HirDatabase,
411 macro_call: Source<&ast::MacroCall>,
412 ) -> Option<Expansion> {
413 let def = self.resolve_macro_call(db, macro_call.value)?.id;
414 let ast_id = AstId::new(
415 macro_call.file_id,
416 db.ast_id_map(macro_call.file_id).ast_id(macro_call.value),
417 );
411 let macro_call_loc = MacroCallLoc { def, ast_id }; 418 let macro_call_loc = MacroCallLoc { def, ast_id };
412 Some(Expansion { macro_call_id: db.intern_macro(macro_call_loc) }) 419 Some(Expansion { macro_call_id: db.intern_macro(macro_call_loc) })
413 } 420 }
diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs
deleted file mode 100644
index 858972c6f..000000000
--- a/crates/ra_hir/src/traits.rs
+++ /dev/null
@@ -1,82 +0,0 @@
1//! HIR for trait definitions.
2
3use std::sync::Arc;
4
5use hir_expand::name::AsName;
6
7use ra_syntax::ast::{self, NameOwner};
8use rustc_hash::FxHashMap;
9
10use crate::{
11 db::{AstDatabase, DefDatabase},
12 ids::LocationCtx,
13 AssocItem, Const, Function, HasSource, Module, Name, Trait, TypeAlias,
14};
15
16#[derive(Debug, Clone, PartialEq, Eq)]
17pub struct TraitData {
18 name: Option<Name>,
19 items: Vec<AssocItem>,
20 auto: bool,
21}
22
23impl TraitData {
24 pub(crate) fn trait_data_query(
25 db: &(impl DefDatabase + AstDatabase),
26 tr: Trait,
27 ) -> Arc<TraitData> {
28 let src = tr.source(db);
29 let name = src.value.name().map(|n| n.as_name());
30 let module = tr.module(db);
31 let ctx = LocationCtx::new(db, module.id, src.file_id);
32 let auto = src.value.is_auto();
33 let items = if let Some(item_list) = src.value.item_list() {
34 item_list
35 .impl_items()
36 .map(|item_node| match item_node {
37 ast::ImplItem::FnDef(it) => Function { id: ctx.to_def(&it) }.into(),
38 ast::ImplItem::ConstDef(it) => Const { id: ctx.to_def(&it) }.into(),
39 ast::ImplItem::TypeAliasDef(it) => TypeAlias { id: ctx.to_def(&it) }.into(),
40 })
41 .collect()
42 } else {
43 Vec::new()
44 };
45 Arc::new(TraitData { name, items, auto })
46 }
47
48 pub(crate) fn name(&self) -> &Option<Name> {
49 &self.name
50 }
51
52 pub(crate) fn items(&self) -> &[AssocItem] {
53 &self.items
54 }
55
56 pub(crate) fn is_auto(&self) -> bool {
57 self.auto
58 }
59}
60
61#[derive(Debug, Clone, PartialEq, Eq)]
62pub struct TraitItemsIndex {
63 traits_by_def: FxHashMap<AssocItem, Trait>,
64}
65
66impl TraitItemsIndex {
67 pub(crate) fn trait_items_index(db: &impl DefDatabase, module: Module) -> TraitItemsIndex {
68 let mut index = TraitItemsIndex { traits_by_def: FxHashMap::default() };
69 for decl in module.declarations(db) {
70 if let crate::ModuleDef::Trait(tr) = decl {
71 for item in tr.trait_data(db).items() {
72 index.traits_by_def.insert(*item, tr);
73 }
74 }
75 }
76 index
77 }
78
79 pub(crate) fn get_parent_trait(&self, item: AssocItem) -> Option<Trait> {
80 self.traits_by_def.get(&item).cloned()
81 }
82}
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index d20aeaacf..f377fca48 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -232,8 +232,8 @@ fn iterate_trait_method_candidates<T>(
232 // trait, but if we find out it doesn't, we'll skip the rest of the 232 // trait, but if we find out it doesn't, we'll skip the rest of the
233 // iteration 233 // iteration
234 let mut known_implemented = false; 234 let mut known_implemented = false;
235 for &item in data.items() { 235 for &item in data.items.iter() {
236 if !is_valid_candidate(db, name, mode, item) { 236 if !is_valid_candidate(db, name, mode, item.into()) {
237 continue; 237 continue;
238 } 238 }
239 if !known_implemented { 239 if !known_implemented {
@@ -243,7 +243,7 @@ fn iterate_trait_method_candidates<T>(
243 } 243 }
244 } 244 }
245 known_implemented = true; 245 known_implemented = true;
246 if let Some(result) = callback(&ty.value, item) { 246 if let Some(result) = callback(&ty.value, item.into()) {
247 return Some(result); 247 return Some(result);
248 } 248 }
249 } 249 }