From 8ac3d1f9aa892fc891b69c7d8d00d39b9371d246 Mon Sep 17 00:00:00 2001 From: Marco Groppo Date: Thu, 18 Apr 2019 20:34:10 +0200 Subject: lang_item_lookup is now a salsa query. --- crates/ra_hir/src/lang_item.rs | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'crates/ra_hir/src/lang_item.rs') diff --git a/crates/ra_hir/src/lang_item.rs b/crates/ra_hir/src/lang_item.rs index a25d419e7..5f3f91cba 100644 --- a/crates/ra_hir/src/lang_item.rs +++ b/crates/ra_hir/src/lang_item.rs @@ -40,7 +40,7 @@ impl LangItems { self.items.get(item) } - /// Salsa query. This will query a specific crate for lang items. + /// Salsa query. This will look for lang items in a specific crate. pub(crate) fn lang_items_query(db: &impl DefDatabase, krate: Crate) -> Arc { let mut lang_items = LangItems { items: FxHashMap::default() }; @@ -51,6 +51,29 @@ impl LangItems { Arc::new(lang_items) } + /// Salsa query. Look for a lang item, starting from the specified crate and recursively + /// traversing its dependencies. + pub(crate) fn lang_item_query( + db: &impl DefDatabase, + start_crate: Crate, + item: SmolStr, + ) -> Option { + let lang_items = db.lang_items(start_crate); + let start_crate_target = lang_items.items.get(&item); + if let Some(target) = start_crate_target { + Some(*target) + } else { + for dep in start_crate.dependencies(db) { + let dep_crate = dep.krate; + let dep_target = db.lang_item(dep_crate, item.clone()); + if dep_target.is_some() { + return dep_target; + } + } + None + } + } + fn collect_lang_items_recursive(&mut self, db: &impl DefDatabase, module: &Module) { // Look for impl targets let (impl_blocks, source_map) = db.impls_in_module_with_source_map(module.clone()); @@ -77,26 +100,3 @@ impl LangItems { } } } - -/// Look for a lang item, starting from the specified crate and recursively traversing its -/// dependencies. -pub(crate) fn lang_item_lookup( - db: &impl DefDatabase, - start_krate: Crate, - item: &str, -) -> Option { - let lang_items = db.lang_items(start_krate); - let start_krate_target = lang_items.items.get(item); - if start_krate_target.is_some() { - start_krate_target.map(|t| *t) - } else { - for dep in start_krate.dependencies(db) { - let dep_krate = dep.krate; - let dep_target = lang_item_lookup(db, dep_krate, item); - if dep_target.is_some() { - return dep_target; - } - } - None - } -} -- cgit v1.2.3