//! Macro input conditioning.
-use parser::SyntaxKind;
use syntax::{
ast::{self, AttrsOwner},
- AstNode, SyntaxElement, SyntaxNode,
+ AstNode, SyntaxNode,
};
use crate::{
let loc: MacroCallLoc = db.lookup_intern_macro(id);
match loc.kind {
- MacroCallKind::FnLike { .. } => {
- if !loc.def.is_proc_macro() {
- // MBE macros expect the parentheses as part of their input.
- return node;
- }
-
- // The input includes the `(` + `)` delimiter tokens, so remove them before passing this
- // to the macro.
- let node = node.clone_for_update();
- if let Some(SyntaxElement::Token(tkn)) = node.first_child_or_token() {
- if matches!(
- tkn.kind(),
- SyntaxKind::L_BRACK | SyntaxKind::L_PAREN | SyntaxKind::L_CURLY
- ) {
- tkn.detach();
- }
- }
- if let Some(SyntaxElement::Token(tkn)) = node.last_child_or_token() {
- if matches!(
- tkn.kind(),
- SyntaxKind::R_BRACK | SyntaxKind::R_PAREN | SyntaxKind::R_CURLY
- ) {
- tkn.detach();
- }
- }
- node
- }
+ MacroCallKind::FnLike { .. } => node,
MacroCallKind::Derive { derive_attr_index, .. } => {
let item = match ast::Item::cast(node.clone()) {
Some(item) => item,
};
Either::Left(*id)
}
-
- pub fn is_proc_macro(&self) -> bool {
- matches!(self.kind, MacroDefKind::ProcMacro(..))
- }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]