From e78221bc58a050e8651f5be591561e7adf89c371 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 12 May 2021 01:01:51 +0200 Subject: Remove delimiters from proc macro input --- crates/hir_expand/src/db.rs | 11 ++++++++++- crates/hir_expand/src/lib.rs | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'crates/hir_expand') diff --git a/crates/hir_expand/src/db.rs b/crates/hir_expand/src/db.rs index 9fa419fcf..c43d382ad 100644 --- a/crates/hir_expand/src/db.rs +++ b/crates/hir_expand/src/db.rs @@ -267,7 +267,16 @@ fn parse_macro_expansion( fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option> { let arg = db.macro_arg_text(id)?; - let (tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg)); + let (mut tt, tmap) = mbe::syntax_node_to_token_tree(&SyntaxNode::new_root(arg)); + + if let MacroCallId::LazyMacro(id) = id { + let loc: MacroCallLoc = db.lookup_intern_macro(id); + if loc.def.is_proc_macro() { + // proc macros expect their inputs without parentheses, MBEs expect it with them included + tt.delimiter = None; + } + } + Some(Arc::new((tt, tmap))) } 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 { }; Either::Left(*id) } + + pub fn is_proc_macro(&self) -> bool { + matches!(self.kind, MacroDefKind::ProcMacro(..)) + } } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -- cgit v1.2.3