From 7c4eb66c1acf10216fa866e05d646bdaea229ded Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 22 Mar 2021 15:56:59 +0100 Subject: Merge hir::MacroDef::is_* into hir::MacroDef::kind --- crates/hir/src/lib.rs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'crates/hir/src/lib.rs') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index ea0a60961..5da6a0340 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -1116,6 +1116,14 @@ impl BuiltinType { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum MacroKind { + Declarative, + ProcMacro, + Derive, + BuiltIn, +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct MacroDef { pub(crate) id: MacroDefId, @@ -1140,20 +1148,15 @@ impl MacroDef { } } - /// Indicate it is a proc-macro - pub fn is_proc_macro(&self) -> bool { - matches!(self.id.kind, MacroDefKind::ProcMacro(..)) - } - - /// Indicate it is a derive macro - pub fn is_derive_macro(&self) -> bool { - // FIXME: wrong for `ProcMacro` - matches!(self.id.kind, MacroDefKind::ProcMacro(..) | MacroDefKind::BuiltInDerive(..)) - } - - /// Indicate it is a declarative macro - pub fn is_declarative(&self) -> bool { - matches!(self.id.kind, MacroDefKind::Declarative(..)) + pub fn kind(&self) -> MacroKind { + match self.id.kind { + MacroDefKind::Declarative(_) => MacroKind::Declarative, + MacroDefKind::BuiltIn(_, _) => MacroKind::BuiltIn, + MacroDefKind::BuiltInDerive(_, _) => MacroKind::Derive, + MacroDefKind::BuiltInEager(_, _) => MacroKind::BuiltIn, + // FIXME might be a derive + MacroDefKind::ProcMacro(_, _) => MacroKind::ProcMacro, + } } } -- cgit v1.2.3