aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model.rs7
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs6
-rw-r--r--crates/ra_hir_def/src/data.rs55
3 files changed, 43 insertions, 25 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 9930cff66..9e7a1deec 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -737,14 +737,11 @@ impl Trait {
737 } 737 }
738 738
739 pub fn items(self, db: &impl DefDatabase) -> Vec<AssocItem> { 739 pub fn items(self, db: &impl DefDatabase) -> Vec<AssocItem> {
740 db.trait_data(self.id).items.iter().map(|it| (*it).into()).collect() 740 db.trait_data(self.id).items.iter().map(|(_name, it)| (*it).into()).collect()
741 } 741 }
742 742
743 pub fn associated_type_by_name(self, db: &impl DefDatabase, name: &Name) -> Option<TypeAlias> { 743 pub fn associated_type_by_name(self, db: &impl DefDatabase, name: &Name) -> Option<TypeAlias> {
744 let trait_data = db.trait_data(self.id); 744 db.trait_data(self.id).associated_type_by_name(name).map(TypeAlias::from)
745 let res =
746 trait_data.associated_types().map(TypeAlias::from).find(|t| &t.name(db) == name)?;
747 Some(res)
748 } 745 }
749 746
750 pub fn associated_type_by_name_including_super_traits( 747 pub fn associated_type_by_name_including_super_traits(
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index 0e18684ed..9988570e8 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -261,8 +261,8 @@ fn iterate_trait_method_candidates<T>(
261 // trait, but if we find out it doesn't, we'll skip the rest of the 261 // trait, but if we find out it doesn't, we'll skip the rest of the
262 // iteration 262 // iteration
263 let mut known_implemented = false; 263 let mut known_implemented = false;
264 for &item in data.items.iter() { 264 for (_name, item) in data.items.iter() {
265 if !is_valid_candidate(db, name, mode, item.into()) { 265 if !is_valid_candidate(db, name, mode, (*item).into()) {
266 continue; 266 continue;
267 } 267 }
268 if !known_implemented { 268 if !known_implemented {
@@ -272,7 +272,7 @@ fn iterate_trait_method_candidates<T>(
272 } 272 }
273 } 273 }
274 known_implemented = true; 274 known_implemented = true;
275 if let Some(result) = callback(&ty.value, item.into()) { 275 if let Some(result) = callback(&ty.value, (*item).into()) {
276 return Some(result); 276 return Some(result);
277 } 277 }
278 } 278 }
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index 68bea34df..813099a05 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -87,7 +87,7 @@ impl TypeAliasData {
87#[derive(Debug, Clone, PartialEq, Eq)] 87#[derive(Debug, Clone, PartialEq, Eq)]
88pub struct TraitData { 88pub struct TraitData {
89 pub name: Option<Name>, 89 pub name: Option<Name>,
90 pub items: Vec<AssocItemId>, 90 pub items: Vec<(Name, AssocItemId)>,
91 pub auto: bool, 91 pub auto: bool,
92} 92}
93 93
@@ -97,28 +97,42 @@ impl TraitData {
97 let name = src.value.name().map(|n| n.as_name()); 97 let name = src.value.name().map(|n| n.as_name());
98 let auto = src.value.is_auto(); 98 let auto = src.value.is_auto();
99 let ast_id_map = db.ast_id_map(src.file_id); 99 let ast_id_map = db.ast_id_map(src.file_id);
100
101 let container = ContainerId::TraitId(tr);
100 let items = if let Some(item_list) = src.value.item_list() { 102 let items = if let Some(item_list) = src.value.item_list() {
101 item_list 103 item_list
102 .impl_items() 104 .impl_items()
103 .map(|item_node| match item_node { 105 .map(|item_node| match item_node {
104 ast::ImplItem::FnDef(it) => FunctionLoc { 106 ast::ImplItem::FnDef(it) => {
105 container: ContainerId::TraitId(tr), 107 let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing);
106 ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), 108 let def = FunctionLoc {
109 container,
110 ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)),
111 }
112 .intern(db)
113 .into();
114 (name, def)
107 } 115 }
108 .intern(db) 116 ast::ImplItem::ConstDef(it) => {
109 .into(), 117 let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing);
110 ast::ImplItem::ConstDef(it) => ConstLoc { 118 let def = ConstLoc {
111 container: ContainerId::TraitId(tr), 119 container,
112 ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), 120 ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)),
121 }
122 .intern(db)
123 .into();
124 (name, def)
113 } 125 }
114 .intern(db) 126 ast::ImplItem::TypeAliasDef(it) => {
115 .into(), 127 let name = it.name().map(|it| it.as_name()).unwrap_or_else(Name::missing);
116 ast::ImplItem::TypeAliasDef(it) => TypeAliasLoc { 128 let def = TypeAliasLoc {
117 container: ContainerId::TraitId(tr), 129 container,
118 ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)), 130 ast_id: AstId::new(src.file_id, ast_id_map.ast_id(&it)),
131 }
132 .intern(db)
133 .into();
134 (name, def)
119 } 135 }
120 .intern(db)
121 .into(),
122 }) 136 })
123 .collect() 137 .collect()
124 } else { 138 } else {
@@ -128,11 +142,18 @@ impl TraitData {
128 } 142 }
129 143
130 pub fn associated_types(&self) -> impl Iterator<Item = TypeAliasId> + '_ { 144 pub fn associated_types(&self) -> impl Iterator<Item = TypeAliasId> + '_ {
131 self.items.iter().filter_map(|item| match item { 145 self.items.iter().filter_map(|(_name, item)| match item {
132 AssocItemId::TypeAliasId(t) => Some(*t), 146 AssocItemId::TypeAliasId(t) => Some(*t),
133 _ => None, 147 _ => None,
134 }) 148 })
135 } 149 }
150
151 pub fn associated_type_by_name(&self, name: &Name) -> Option<TypeAliasId> {
152 self.items.iter().find_map(|(item_name, item)| match item {
153 AssocItemId::TypeAliasId(t) if item_name == name => Some(*t),
154 _ => None,
155 })
156 }
136} 157}
137 158
138#[derive(Debug, Clone, PartialEq, Eq)] 159#[derive(Debug, Clone, PartialEq, Eq)]