From e5a2c6596ddd11b0d57042224ac7c1d7691ec33b Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 31 May 2021 13:37:11 +0200 Subject: Expand procedural attribute macros --- crates/hir_expand/src/input.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'crates/hir_expand/src/input.rs') 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( remove_derives_up_to(item, derive_attr_index as usize).syntax().clone() } + MacroCallKind::Attr { invoc_attr_index, .. } => { + let item = match ast::Item::cast(node.clone()) { + Some(item) => item, + None => return node, + }; + + remove_attr_invoc(item, invoc_attr_index as usize).syntax().clone() + } } } @@ -46,6 +54,17 @@ fn remove_derives_up_to(item: ast::Item, attr_index: usize) -> ast::Item { item } +/// Removes the attribute invoking an attribute macro from `item`. +fn remove_attr_invoc(item: ast::Item, attr_index: usize) -> ast::Item { + let item = item.clone_for_update(); + let attr = item + .attrs() + .nth(attr_index) + .unwrap_or_else(|| panic!("cannot find attribute #{}", attr_index)); + attr.syntax().detach(); + item +} + #[cfg(test)] mod tests { use base_db::fixture::WithFixture; -- cgit v1.2.3