}
}
+#[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,
}
}
- /// 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,
+ }
}
}
let mut result = FxHashSet::default();
ctx.scope.process_all_names(&mut |name, scope_def| {
if let hir::ScopeDef::MacroDef(mac) = scope_def {
- if mac.is_derive_macro() {
+ // FIXME kind() doesn't check whether proc-macro is a derive
+ if mac.kind() == hir::MacroKind::Derive || mac.kind() == hir::MacroKind::ProcMacro {
result.insert(name.to_string());
}
}