Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir/src/lib.rs')
-rw-r--r--crates/hir/src/lib.rs49
1 files changed, 21 insertions, 28 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 727d31cffb..55448d4ae8 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -142,7 +142,7 @@ pub use {
name::Name,
prettify_macro_expansion,
proc_macro::{ProcMacros, ProcMacrosBuilder},
- tt, ExpandResult, HirFileId, HirFileIdExt, MacroFileId, MacroFileIdExt,
+ tt, ExpandResult, HirFileId, HirFileIdExt, MacroFileId, MacroFileIdExt, MacroKind,
},
hir_ty::{
consteval::ConstEvalError,
@@ -699,7 +699,10 @@ impl Module {
let source_map = tree_source_maps.impl_(loc.id.value).item();
let node = &tree[loc.id.value];
let file_id = loc.id.file_id();
- if file_id.macro_file().is_some_and(|it| it.is_builtin_derive(db.upcast())) {
+ if file_id
+ .macro_file()
+ .is_some_and(|it| it.kind(db.upcast()) == MacroKind::DeriveBuiltIn)
+ {
// these expansion come from us, diagnosing them is a waste of resources
// FIXME: Once we diagnose the inputs to builtin derives, we should at least extract those diagnostics somehow
continue;
@@ -3050,20 +3053,6 @@ impl BuiltinType {
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
-pub enum MacroKind {
- /// `macro_rules!` or Macros 2.0 macro.
- Declarative,
- /// A built-in or custom derive.
- Derive,
- /// A built-in function-like macro.
- BuiltIn,
- /// A procedural attribute macro.
- Attr,
- /// A function-like procedural macro.
- ProcMacro,
-}
-
-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Macro {
pub(crate) id: MacroId,
}
@@ -3093,15 +3082,19 @@ impl Macro {
match self.id {
MacroId::Macro2Id(it) => match it.lookup(db.upcast()).expander {
MacroExpander::Declarative => MacroKind::Declarative,
- MacroExpander::BuiltIn(_) | MacroExpander::BuiltInEager(_) => MacroKind::BuiltIn,
- MacroExpander::BuiltInAttr(_) => MacroKind::Attr,
- MacroExpander::BuiltInDerive(_) => MacroKind::Derive,
+ MacroExpander::BuiltIn(_) | MacroExpander::BuiltInEager(_) => {
+ MacroKind::DeclarativeBuiltIn
+ }
+ MacroExpander::BuiltInAttr(_) => MacroKind::AttrBuiltIn,
+ MacroExpander::BuiltInDerive(_) => MacroKind::DeriveBuiltIn,
},
MacroId::MacroRulesId(it) => match it.lookup(db.upcast()).expander {
MacroExpander::Declarative => MacroKind::Declarative,
- MacroExpander::BuiltIn(_) | MacroExpander::BuiltInEager(_) => MacroKind::BuiltIn,
- MacroExpander::BuiltInAttr(_) => MacroKind::Attr,
- MacroExpander::BuiltInDerive(_) => MacroKind::Derive,
+ MacroExpander::BuiltIn(_) | MacroExpander::BuiltInEager(_) => {
+ MacroKind::DeclarativeBuiltIn
+ }
+ MacroExpander::BuiltInAttr(_) => MacroKind::AttrBuiltIn,
+ MacroExpander::BuiltInDerive(_) => MacroKind::DeriveBuiltIn,
},
MacroId::ProcMacroId(it) => match it.lookup(db.upcast()).kind {
ProcMacroKind::CustomDerive => MacroKind::Derive,
@@ -3112,10 +3105,10 @@ impl Macro {
}
pub fn is_fn_like(&self, db: &dyn HirDatabase) -> bool {
- match self.kind(db) {
- MacroKind::Declarative | MacroKind::BuiltIn | MacroKind::ProcMacro => true,
- MacroKind::Attr | MacroKind::Derive => false,
- }
+ matches!(
+ self.kind(db),
+ MacroKind::Declarative | MacroKind::DeclarativeBuiltIn | MacroKind::ProcMacro
+ )
}
pub fn is_builtin_derive(&self, db: &dyn HirDatabase) -> bool {
@@ -3155,11 +3148,11 @@ impl Macro {
}
pub fn is_attr(&self, db: &dyn HirDatabase) -> bool {
- matches!(self.kind(db), MacroKind::Attr)
+ matches!(self.kind(db), MacroKind::Attr | MacroKind::AttrBuiltIn)
}
pub fn is_derive(&self, db: &dyn HirDatabase) -> bool {
- matches!(self.kind(db), MacroKind::Derive)
+ matches!(self.kind(db), MacroKind::Derive | MacroKind::DeriveBuiltIn)
}
}