From 02c2beaa8c54201863ab4713f6f42cd98ae3951c Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 22 May 2020 15:55:15 +0200 Subject: Provide Chalk well-known traits --- crates/ra_hir_def/src/lang_item.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs index d96ac8c0a..d962db3cc 100644 --- a/crates/ra_hir_def/src/lang_item.rs +++ b/crates/ra_hir_def/src/lang_item.rs @@ -73,8 +73,8 @@ pub struct LangItems { } impl LangItems { - pub fn target<'a>(&'a self, item: &str) -> Option<&'a LangItemTarget> { - self.items.get(item) + pub fn target(&self, item: &str) -> Option { + self.items.get(item).copied() } /// Salsa query. This will look for lang items in a specific crate. @@ -163,9 +163,13 @@ impl LangItems { ) where T: Into + Copy, { - let attrs = db.attrs(item.into()); - if let Some(lang_item_name) = attrs.by_key("lang").string_value() { + if let Some(lang_item_name) = lang_attr(db, item) { self.items.entry(lang_item_name.clone()).or_insert_with(|| constructor(item)); } } } + +pub fn lang_attr(db: &dyn DefDatabase, item: impl Into + Copy) -> Option { + let attrs = db.attrs(item.into()); + attrs.by_key("lang").string_value().cloned() +} -- cgit v1.2.3