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.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/crates/hir-def/src/attr.rs b/crates/hir-def/src/attr.rs
index fa7730f302..d9eeffd798 100644
--- a/crates/hir-def/src/attr.rs
+++ b/crates/hir-def/src/attr.rs
@@ -5,7 +5,7 @@ pub mod builtin;
#[cfg(test)]
mod tests;
-use std::{hash::Hash, ops, slice::Iter as SliceIter};
+use std::{borrow::Cow, hash::Hash, ops, slice::Iter as SliceIter};
use base_db::CrateId;
use cfg::{CfgExpr, CfgOptions};
@@ -141,6 +141,10 @@ impl Attrs {
}
}
+ pub fn cfgs(&self) -> impl Iterator<Item = CfgExpr> + '_ {
+ self.by_key("cfg").tt_values().map(CfgExpr::parse)
+ }
+
pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> bool {
match self.cfg() {
None => true,
@@ -569,6 +573,10 @@ impl<'attr> AttrQuery<'attr> {
self.attrs().find_map(|attr| attr.string_value())
}
+ pub fn string_value_unescape(self) -> Option<Cow<'attr, str>> {
+ self.attrs().find_map(|attr| attr.string_value_unescape())
+ }
+
pub fn exists(self) -> bool {
self.attrs().next().is_some()
}