Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/nameres/assoc.rs')
-rw-r--r--crates/hir-def/src/nameres/assoc.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/crates/hir-def/src/nameres/assoc.rs b/crates/hir-def/src/nameres/assoc.rs
index 448b908936..86225d33b4 100644
--- a/crates/hir-def/src/nameres/assoc.rs
+++ b/crates/hir-def/src/nameres/assoc.rs
@@ -66,7 +66,16 @@ impl TraitItems {
})
}
- pub fn attribute_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
+ pub fn assoc_item_by_name(&self, name: &Name) -> Option<AssocItemId> {
+ self.items.iter().find_map(|&(ref item_name, item)| match item {
+ AssocItemId::FunctionId(_) if item_name == name => Some(item),
+ AssocItemId::TypeAliasId(_) if item_name == name => Some(item),
+ AssocItemId::ConstId(_) if item_name == name => Some(item),
+ _ => None,
+ })
+ }
+
+ pub fn macro_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
self.macro_calls.iter().flat_map(|it| it.iter()).copied()
}
}
@@ -100,7 +109,7 @@ impl ImplItems {
(Arc::new(ImplItems { items, macro_calls }), DefDiagnostics::new(diagnostics))
}
- pub fn attribute_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
+ pub fn macro_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
self.macro_calls.iter().flat_map(|it| it.iter()).copied()
}
}
@@ -108,8 +117,8 @@ impl ImplItems {
struct AssocItemCollector<'a> {
db: &'a dyn DefDatabase,
module_id: ModuleId,
- def_map: Arc<DefMap>,
- local_def_map: Arc<LocalDefMap>,
+ def_map: &'a DefMap,
+ local_def_map: &'a LocalDefMap,
diagnostics: Vec<DefDiagnostic>,
container: ItemContainerId,
@@ -174,7 +183,7 @@ impl<'a> AssocItemCollector<'a> {
let ast_id_with_path = AstIdWithPath { path: attr.path.clone(), ast_id };
match self.def_map.resolve_attr_macro(
- &self.local_def_map,
+ self.local_def_map,
self.db,
self.module_id.local_id,
ast_id_with_path,
@@ -246,7 +255,7 @@ impl<'a> AssocItemCollector<'a> {
let resolver = |path: &_| {
self.def_map
.resolve_path(
- &self.local_def_map,
+ self.local_def_map,
self.db,
self.module_id.local_id,
path,