diff options
author | Jonas Schievink <[email protected]> | 2021-05-31 12:37:11 +0100 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2021-06-03 17:09:21 +0100 |
commit | e5a2c6596ddd11b0d57042224ac7c1d7691ec33b (patch) | |
tree | f0476ad40103b5d3dea60f81fca32c63fe9618d7 /crates/hir_expand/src/input.rs | |
parent | 7f9c4a59d9a84cd8c734286937439b5cd215be27 (diff) |
Expand procedural attribute macros
Diffstat (limited to 'crates/hir_expand/src/input.rs')
-rw-r--r-- | crates/hir_expand/src/input.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/hir_expand/src/input.rs b/crates/hir_expand/src/input.rs index fe4790e7b..40116a479 100644 --- a/crates/hir_expand/src/input.rs +++ b/crates/hir_expand/src/input.rs | |||
@@ -28,6 +28,14 @@ pub(crate) fn process_macro_input( | |||
28 | 28 | ||
29 | remove_derives_up_to(item, derive_attr_index as usize).syntax().clone() | 29 | remove_derives_up_to(item, derive_attr_index as usize).syntax().clone() |
30 | } | 30 | } |
31 | MacroCallKind::Attr { invoc_attr_index, .. } => { | ||
32 | let item = match ast::Item::cast(node.clone()) { | ||
33 | Some(item) => item, | ||
34 | None => return node, | ||
35 | }; | ||
36 | |||
37 | remove_attr_invoc(item, invoc_attr_index as usize).syntax().clone() | ||
38 | } | ||
31 | } | 39 | } |
32 | } | 40 | } |
33 | 41 | ||
@@ -46,6 +54,17 @@ fn remove_derives_up_to(item: ast::Item, attr_index: usize) -> ast::Item { | |||
46 | item | 54 | item |
47 | } | 55 | } |
48 | 56 | ||
57 | /// Removes the attribute invoking an attribute macro from `item`. | ||
58 | fn remove_attr_invoc(item: ast::Item, attr_index: usize) -> ast::Item { | ||
59 | let item = item.clone_for_update(); | ||
60 | let attr = item | ||
61 | .attrs() | ||
62 | .nth(attr_index) | ||
63 | .unwrap_or_else(|| panic!("cannot find attribute #{}", attr_index)); | ||
64 | attr.syntax().detach(); | ||
65 | item | ||
66 | } | ||
67 | |||
49 | #[cfg(test)] | 68 | #[cfg(test)] |
50 | mod tests { | 69 | mod tests { |
51 | use base_db::fixture::WithFixture; | 70 | use base_db::fixture::WithFixture; |