aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_expand/src')
-rw-r--r--crates/hir_expand/src/input.rs31
-rw-r--r--crates/hir_expand/src/lib.rs4
2 files changed, 33 insertions, 2 deletions
diff --git a/crates/hir_expand/src/input.rs b/crates/hir_expand/src/input.rs
index 112216859..860aa049b 100644
--- a/crates/hir_expand/src/input.rs
+++ b/crates/hir_expand/src/input.rs
@@ -1,8 +1,9 @@
1//! Macro input conditioning. 1//! Macro input conditioning.
2 2
3use parser::SyntaxKind;
3use syntax::{ 4use syntax::{
4 ast::{self, AttrsOwner}, 5 ast::{self, AttrsOwner},
5 AstNode, SyntaxNode, 6 AstNode, SyntaxElement, SyntaxNode,
6}; 7};
7 8
8use crate::{ 9use crate::{
@@ -19,7 +20,33 @@ pub(crate) fn process_macro_input(
19 let loc: MacroCallLoc = db.lookup_intern_macro(id); 20 let loc: MacroCallLoc = db.lookup_intern_macro(id);
20 21
21 match loc.kind { 22 match loc.kind {
22 MacroCallKind::FnLike { .. } => node, 23 MacroCallKind::FnLike { .. } => {
24 if !loc.def.is_proc_macro() {
25 // MBE macros expect the parentheses as part of their input.
26 return node;
27 }
28
29 // The input includes the `(` + `)` delimiter tokens, so remove them before passing this
30 // to the macro.
31 let node = node.clone_for_update();
32 if let Some(SyntaxElement::Token(tkn)) = node.first_child_or_token() {
33 if matches!(
34 tkn.kind(),
35 SyntaxKind::L_BRACK | SyntaxKind::L_PAREN | SyntaxKind::L_CURLY
36 ) {
37 tkn.detach();
38 }
39 }
40 if let Some(SyntaxElement::Token(tkn)) = node.last_child_or_token() {
41 if matches!(
42 tkn.kind(),
43 SyntaxKind::R_BRACK | SyntaxKind::R_PAREN | SyntaxKind::R_CURLY
44 ) {
45 tkn.detach();
46 }
47 }
48 node
49 }
23 MacroCallKind::Derive { derive_attr_index, .. } => { 50 MacroCallKind::Derive { derive_attr_index, .. } => {
24 let item = match ast::Item::cast(node.clone()) { 51 let item = match ast::Item::cast(node.clone()) {
25 Some(item) => item, 52 Some(item) => item,
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 5df11856e..88cb16ca4 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -272,6 +272,10 @@ impl MacroDefId {
272 }; 272 };
273 Either::Left(*id) 273 Either::Left(*id)
274 } 274 }
275
276 pub fn is_proc_macro(&self) -> bool {
277 matches!(self.kind, MacroDefKind::ProcMacro(..))
278 }
275} 279}
276 280
277#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 281#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]