diff options
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/lib.rs | 31 |
1 files changed, 17 insertions, 14 deletions
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 | |||
@@ -1117,6 +1117,14 @@ impl BuiltinType { | |||
1117 | } | 1117 | } |
1118 | 1118 | ||
1119 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 1119 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
1120 | pub enum MacroKind { | ||
1121 | Declarative, | ||
1122 | ProcMacro, | ||
1123 | Derive, | ||
1124 | BuiltIn, | ||
1125 | } | ||
1126 | |||
1127 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
1120 | pub struct MacroDef { | 1128 | pub struct MacroDef { |
1121 | pub(crate) id: MacroDefId, | 1129 | pub(crate) id: MacroDefId, |
1122 | } | 1130 | } |
@@ -1140,20 +1148,15 @@ impl MacroDef { | |||
1140 | } | 1148 | } |
1141 | } | 1149 | } |
1142 | 1150 | ||
1143 | /// Indicate it is a proc-macro | 1151 | pub fn kind(&self) -> MacroKind { |
1144 | pub fn is_proc_macro(&self) -> bool { | 1152 | match self.id.kind { |
1145 | matches!(self.id.kind, MacroDefKind::ProcMacro(..)) | 1153 | MacroDefKind::Declarative(_) => MacroKind::Declarative, |
1146 | } | 1154 | MacroDefKind::BuiltIn(_, _) => MacroKind::BuiltIn, |
1147 | 1155 | MacroDefKind::BuiltInDerive(_, _) => MacroKind::Derive, | |
1148 | /// Indicate it is a derive macro | 1156 | MacroDefKind::BuiltInEager(_, _) => MacroKind::BuiltIn, |
1149 | pub fn is_derive_macro(&self) -> bool { | 1157 | // FIXME might be a derive |
1150 | // FIXME: wrong for `ProcMacro` | 1158 | MacroDefKind::ProcMacro(_, _) => MacroKind::ProcMacro, |
1151 | matches!(self.id.kind, MacroDefKind::ProcMacro(..) | MacroDefKind::BuiltInDerive(..)) | 1159 | } |
1152 | } | ||
1153 | |||
1154 | /// Indicate it is a declarative macro | ||
1155 | pub fn is_declarative(&self) -> bool { | ||
1156 | matches!(self.id.kind, MacroDefKind::Declarative(..)) | ||
1157 | } | 1160 | } |
1158 | } | 1161 | } |
1159 | 1162 | ||