aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand/src/input.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-11 23:27:50 +0100
committerGitHub <[email protected]>2021-05-11 23:27:50 +0100
commitc6e2ba43bbfef80d4ecabbc9edd5be9d058f6db9 (patch)
tree3fba6b5419e7b39dd922387d12c90e3111845b11 /crates/hir_expand/src/input.rs
parentacde43f7c945e4f6728b1a3614d517894f6c5579 (diff)
parentbda68e23328ca62a71da348a13c4d13cc8f991f3 (diff)
Merge #8806
8806: fix: Strip delimiter from fn-like macro invocations r=jonas-schievink a=jonas-schievink This broke in https://github.com/rust-analyzer/rust-analyzer/pull/8796 (again), the fix is easy though bors r+ Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_expand/src/input.rs')
-rw-r--r--crates/hir_expand/src/input.rs31
1 files changed, 29 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,