aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/traits.rs')
-rw-r--r--crates/ra_hir_def/src/traits.rs25
1 files changed, 20 insertions, 5 deletions
diff --git a/crates/ra_hir_def/src/traits.rs b/crates/ra_hir_def/src/traits.rs
index a8ba31594..6e36bc0d0 100644
--- a/crates/ra_hir_def/src/traits.rs
+++ b/crates/ra_hir_def/src/traits.rs
@@ -2,14 +2,17 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_expand::name::{AsName, Name}; 5use hir_expand::{
6 name::{AsName, Name},
7 AstId,
8};
6 9
7use ra_syntax::ast::{self, NameOwner}; 10use ra_syntax::ast::{self, NameOwner};
8use rustc_hash::FxHashMap; 11use rustc_hash::FxHashMap;
9 12
10use crate::{ 13use crate::{
11 db::DefDatabase2, AssocItemId, AstItemDef, ConstId, FunctionId, LocationCtx, ModuleDefId, 14 db::DefDatabase2, AssocItemId, AstItemDef, ConstId, FunctionContainerId, FunctionLoc, Intern,
12 ModuleId, TraitId, TypeAliasId, 15 LocationCtx, ModuleDefId, ModuleId, TraitId, TypeAliasId,
13}; 16};
14 17
15#[derive(Debug, Clone, PartialEq, Eq)] 18#[derive(Debug, Clone, PartialEq, Eq)]
@@ -26,11 +29,17 @@ impl TraitData {
26 let module = tr.module(db); 29 let module = tr.module(db);
27 let ctx = LocationCtx::new(db, module, src.file_id); 30 let ctx = LocationCtx::new(db, module, src.file_id);
28 let auto = src.value.is_auto(); 31 let auto = src.value.is_auto();
32 let ast_id_map = db.ast_id_map(src.file_id);
29 let items = if let Some(item_list) = src.value.item_list() { 33 let items = if let Some(item_list) = src.value.item_list() {
30 item_list 34 item_list
31 .impl_items() 35 .impl_items()
32 .map(|item_node| match item_node { 36 .map(|item_node| match item_node {
33 ast::ImplItem::FnDef(it) => FunctionId::from_ast(ctx, &it).into(), 37 ast::ImplItem::FnDef(it) => FunctionLoc {
38 container: FunctionContainerId::TraitId(tr),
39 ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)),
40 }
41 .intern(db)
42 .into(),
34 ast::ImplItem::ConstDef(it) => ConstId::from_ast(ctx, &it).into(), 43 ast::ImplItem::ConstDef(it) => ConstId::from_ast(ctx, &it).into(),
35 ast::ImplItem::TypeAliasDef(it) => TypeAliasId::from_ast(ctx, &it).into(), 44 ast::ImplItem::TypeAliasDef(it) => TypeAliasId::from_ast(ctx, &it).into(),
36 }) 45 })
@@ -54,7 +63,13 @@ impl TraitItemsIndex {
54 for decl in crate_def_map[module.module_id].scope.declarations() { 63 for decl in crate_def_map[module.module_id].scope.declarations() {
55 if let ModuleDefId::TraitId(tr) = decl { 64 if let ModuleDefId::TraitId(tr) = decl {
56 for item in db.trait_data(tr).items.iter() { 65 for item in db.trait_data(tr).items.iter() {
57 index.traits_by_def.insert(*item, tr); 66 match item {
67 AssocItemId::FunctionId(_) => (),
68 _ => {
69 let prev = index.traits_by_def.insert(*item, tr);
70 assert!(prev.is_none());
71 }
72 }
58 } 73 }
59 } 74 }
60 } 75 }