Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/attr.rs')
| -rw-r--r-- | crates/hir-def/src/attr.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/crates/hir-def/src/attr.rs b/crates/hir-def/src/attr.rs index e4d3636ce5..860df1b68b 100644 --- a/crates/hir-def/src/attr.rs +++ b/crates/hir-def/src/attr.rs @@ -20,6 +20,7 @@ use syntax::{ use crate::{ db::DefDatabase, item_tree::{AttrOwner, Fields, ItemTreeId, ItemTreeNode}, + lang_item::LangItem, nameres::{ModuleOrigin, ModuleSource}, src::{HasChildSource, HasSource}, AdtId, AttrDefId, EnumId, GenericParamId, LocalEnumVariantId, LocalFieldId, Lookup, MacroId, @@ -177,13 +178,13 @@ impl Attrs { Arc::new(res) } +} +impl Attrs { pub fn by_key(&self, key: &'static str) -> AttrQuery<'_> { AttrQuery { attrs: self, key } } -} -impl Attrs { pub fn cfg(&self) -> Option<CfgExpr> { let mut cfgs = self.by_key("cfg").tt_values().map(CfgExpr::parse); let first = cfgs.next()?; @@ -206,6 +207,10 @@ impl Attrs { self.by_key("lang").string_value() } + pub fn lang_item(&self) -> Option<LangItem> { + self.by_key("lang").string_value().and_then(|it| LangItem::from_str(it)) + } + pub fn docs(&self) -> Option<Documentation> { let docs = self.by_key("doc").attrs().filter_map(|attr| attr.string_value()); let indent = doc_indent(self); |