@@ -142,7 +142,7 @@ pub use {
142
142
name:: Name ,
143
143
prettify_macro_expansion,
144
144
proc_macro:: { ProcMacros , ProcMacrosBuilder } ,
145
- tt, ExpandResult , HirFileId , HirFileIdExt , MacroFileId , MacroFileIdExt ,
145
+ tt, ExpandResult , HirFileId , HirFileIdExt , MacroFileId , MacroFileIdExt , MacroKind ,
146
146
} ,
147
147
hir_ty:: {
148
148
consteval:: ConstEvalError ,
@@ -699,7 +699,10 @@ impl Module {
699
699
let source_map = tree_source_maps. impl_ ( loc. id . value ) . item ( ) ;
700
700
let node = & tree[ loc. id . value ] ;
701
701
let file_id = loc. id . file_id ( ) ;
702
- if file_id. macro_file ( ) . is_some_and ( |it| it. is_builtin_derive ( db. upcast ( ) ) ) {
702
+ if file_id
703
+ . macro_file ( )
704
+ . is_some_and ( |it| it. kind ( db. upcast ( ) ) == MacroKind :: DeriveBuiltIn )
705
+ {
703
706
// these expansion come from us, diagnosing them is a waste of resources
704
707
// FIXME: Once we diagnose the inputs to builtin derives, we should at least extract those diagnostics somehow
705
708
continue ;
@@ -3049,20 +3052,6 @@ impl BuiltinType {
3049
3052
}
3050
3053
}
3051
3054
3052
- #[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
3053
- pub enum MacroKind {
3054
- /// `macro_rules!` or Macros 2.0 macro.
3055
- Declarative ,
3056
- /// A built-in or custom derive.
3057
- Derive ,
3058
- /// A built-in function-like macro.
3059
- BuiltIn ,
3060
- /// A procedural attribute macro.
3061
- Attr ,
3062
- /// A function-like procedural macro.
3063
- ProcMacro ,
3064
- }
3065
-
3066
3055
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
3067
3056
pub struct Macro {
3068
3057
pub ( crate ) id : MacroId ,
@@ -3093,15 +3082,19 @@ impl Macro {
3093
3082
match self . id {
3094
3083
MacroId :: Macro2Id ( it) => match it. lookup ( db. upcast ( ) ) . expander {
3095
3084
MacroExpander :: Declarative => MacroKind :: Declarative ,
3096
- MacroExpander :: BuiltIn ( _) | MacroExpander :: BuiltInEager ( _) => MacroKind :: BuiltIn ,
3097
- MacroExpander :: BuiltInAttr ( _) => MacroKind :: Attr ,
3098
- MacroExpander :: BuiltInDerive ( _) => MacroKind :: Derive ,
3085
+ MacroExpander :: BuiltIn ( _) | MacroExpander :: BuiltInEager ( _) => {
3086
+ MacroKind :: DeclarativeBuiltIn
3087
+ }
3088
+ MacroExpander :: BuiltInAttr ( _) => MacroKind :: AttrBuiltIn ,
3089
+ MacroExpander :: BuiltInDerive ( _) => MacroKind :: DeriveBuiltIn ,
3099
3090
} ,
3100
3091
MacroId :: MacroRulesId ( it) => match it. lookup ( db. upcast ( ) ) . expander {
3101
3092
MacroExpander :: Declarative => MacroKind :: Declarative ,
3102
- MacroExpander :: BuiltIn ( _) | MacroExpander :: BuiltInEager ( _) => MacroKind :: BuiltIn ,
3103
- MacroExpander :: BuiltInAttr ( _) => MacroKind :: Attr ,
3104
- MacroExpander :: BuiltInDerive ( _) => MacroKind :: Derive ,
3093
+ MacroExpander :: BuiltIn ( _) | MacroExpander :: BuiltInEager ( _) => {
3094
+ MacroKind :: DeclarativeBuiltIn
3095
+ }
3096
+ MacroExpander :: BuiltInAttr ( _) => MacroKind :: AttrBuiltIn ,
3097
+ MacroExpander :: BuiltInDerive ( _) => MacroKind :: DeriveBuiltIn ,
3105
3098
} ,
3106
3099
MacroId :: ProcMacroId ( it) => match it. lookup ( db. upcast ( ) ) . kind {
3107
3100
ProcMacroKind :: CustomDerive => MacroKind :: Derive ,
@@ -3112,10 +3105,10 @@ impl Macro {
3112
3105
}
3113
3106
3114
3107
pub fn is_fn_like ( & self , db : & dyn HirDatabase ) -> bool {
3115
- match self . kind ( db ) {
3116
- MacroKind :: Declarative | MacroKind :: BuiltIn | MacroKind :: ProcMacro => true ,
3117
- MacroKind :: Attr | MacroKind :: Derive => false ,
3118
- }
3108
+ matches ! (
3109
+ self . kind ( db ) ,
3110
+ MacroKind :: Declarative | MacroKind :: DeclarativeBuiltIn | MacroKind :: ProcMacro
3111
+ )
3119
3112
}
3120
3113
3121
3114
pub fn is_builtin_derive ( & self , db : & dyn HirDatabase ) -> bool {
@@ -3155,11 +3148,11 @@ impl Macro {
3155
3148
}
3156
3149
3157
3150
pub fn is_attr ( & self , db : & dyn HirDatabase ) -> bool {
3158
- matches ! ( self . kind( db) , MacroKind :: Attr )
3151
+ matches ! ( self . kind( db) , MacroKind :: Attr | MacroKind :: AttrBuiltIn )
3159
3152
}
3160
3153
3161
3154
pub fn is_derive ( & self , db : & dyn HirDatabase ) -> bool {
3162
- matches ! ( self . kind( db) , MacroKind :: Derive )
3155
+ matches ! ( self . kind( db) , MacroKind :: Derive | MacroKind :: DeriveBuiltIn )
3163
3156
}
3164
3157
}
3165
3158
0 commit comments