Skip to content

Commit c6e2ba4

Browse files
Merge #8806
8806: fix: Strip delimiter from fn-like macro invocations r=jonas-schievink a=jonas-schievink This broke in #8796 (again), the fix is easy though bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents acde43f + bda68e2 commit c6e2ba4

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

crates/hir_expand/src/input.rs

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Macro input conditioning.
22
3+
use parser::SyntaxKind;
34
use syntax::{
45
ast::{self, AttrsOwner},
5-
AstNode, SyntaxNode,
6+
AstNode, SyntaxElement, SyntaxNode,
67
};
78

89
use crate::{
@@ -19,7 +20,33 @@ pub(crate) fn process_macro_input(
1920
let loc: MacroCallLoc = db.lookup_intern_macro(id);
2021

2122
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+
}
2350
MacroCallKind::Derive { derive_attr_index, .. } => {
2451
let item = match ast::Item::cast(node.clone()) {
2552
Some(item) => item,

crates/hir_expand/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ impl MacroDefId {
272272
};
273273
Either::Left(*id)
274274
}
275+
276+
pub fn is_proc_macro(&self) -> bool {
277+
matches!(self.kind, MacroDefKind::ProcMacro(..))
278+
}
275279
}
276280

277281
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)