diff options
author | Jonas Schievink <[email protected]> | 2020-09-18 15:43:50 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-09-18 15:43:50 +0100 |
commit | 5486b70bc0fa1b6260178fa7e547a534d91c3e04 (patch) | |
tree | ac4a36773afb0e7f33e9e6abdecd07c0216557f5 /crates/hir_def/src/attr.rs | |
parent | dfa3a3f017c39f745f06d96de11359b97c76fc47 (diff) |
Use hir_def to resolve proc macros
Diffstat (limited to 'crates/hir_def/src/attr.rs')
-rw-r--r-- | crates/hir_def/src/attr.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index dea552a60..a841b97bf 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs | |||
@@ -171,6 +171,9 @@ pub struct AttrQuery<'a> { | |||
171 | } | 171 | } |
172 | 172 | ||
173 | impl<'a> AttrQuery<'a> { | 173 | impl<'a> AttrQuery<'a> { |
174 | /// For an attribute like `#[attr(value)]`, returns the `(value)` subtree. | ||
175 | /// | ||
176 | /// If the attribute does not have a token tree argument, returns `None`. | ||
174 | pub fn tt_values(self) -> impl Iterator<Item = &'a Subtree> { | 177 | pub fn tt_values(self) -> impl Iterator<Item = &'a Subtree> { |
175 | self.attrs().filter_map(|attr| match attr.input.as_ref()? { | 178 | self.attrs().filter_map(|attr| match attr.input.as_ref()? { |
176 | AttrInput::TokenTree(it) => Some(it), | 179 | AttrInput::TokenTree(it) => Some(it), |
@@ -178,6 +181,9 @@ impl<'a> AttrQuery<'a> { | |||
178 | }) | 181 | }) |
179 | } | 182 | } |
180 | 183 | ||
184 | /// For an attribute like `#[key = "value"]`, returns `"value"`. | ||
185 | /// | ||
186 | /// Returns `None` if the attribute does not have `key = "value"` form. | ||
181 | pub fn string_value(self) -> Option<&'a SmolStr> { | 187 | pub fn string_value(self) -> Option<&'a SmolStr> { |
182 | self.attrs().find_map(|attr| match attr.input.as_ref()? { | 188 | self.attrs().find_map(|attr| match attr.input.as_ref()? { |
183 | AttrInput::Literal(it) => Some(it), | 189 | AttrInput::Literal(it) => Some(it), |