@@ -8,7 +8,7 @@ use rustc_data_structures::unord::UnordMap;
8
8
use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
9
9
use rustc_span:: Symbol ;
10
10
use rustc_span:: def_id:: { DefId , LocalDefId } ;
11
- use rustc_span:: hygiene:: MacroKinds ;
11
+ use rustc_span:: hygiene:: MacroKind ;
12
12
13
13
use crate :: definitions:: DefPathData ;
14
14
use crate :: hir;
@@ -31,6 +31,53 @@ pub enum CtorKind {
31
31
Const ,
32
32
}
33
33
34
+ /// A set of macro kinds, for macros that can have more than one kind
35
+ #[ derive( Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Encodable , Decodable , Hash , Debug ) ]
36
+ #[ derive( HashStable_Generic ) ]
37
+ pub struct MacroKinds ( u8 ) ;
38
+ bitflags:: bitflags! {
39
+ impl MacroKinds : u8 {
40
+ const BANG = 1 << 0 ;
41
+ const ATTR = 1 << 1 ;
42
+ const DERIVE = 1 << 2 ;
43
+ }
44
+ }
45
+
46
+ impl From < MacroKind > for MacroKinds {
47
+ fn from ( kind : MacroKind ) -> Self {
48
+ match kind {
49
+ MacroKind :: Bang => Self :: BANG ,
50
+ MacroKind :: Attr => Self :: ATTR ,
51
+ MacroKind :: Derive => Self :: DERIVE ,
52
+ }
53
+ }
54
+ }
55
+
56
+ impl MacroKinds {
57
+ /// Convert the MacroKinds to a static string.
58
+ ///
59
+ /// This hardcodes all the possibilities, in order to return a static string.
60
+ pub fn descr ( self ) -> & ' static str {
61
+ match self {
62
+ // FIXME: change this to "function-like macro" and fix all tests
63
+ Self :: BANG => "macro" ,
64
+ Self :: ATTR => "attribute macro" ,
65
+ Self :: DERIVE => "derive macro" ,
66
+ _ if self == ( Self :: ATTR | Self :: BANG ) => "attribute/function macro" ,
67
+ _ if self == ( Self :: DERIVE | Self :: BANG ) => "derive/function macro" ,
68
+ _ if self == ( Self :: ATTR | Self :: DERIVE ) => "attribute/derive macro" ,
69
+ _ if self . is_all ( ) => "attribute/derive/function macro" ,
70
+ _ if self . is_empty ( ) => "useless macro" ,
71
+ _ => unreachable ! ( ) ,
72
+ }
73
+ }
74
+
75
+ /// Return an indefinite article (a/an) for use with `descr()`
76
+ pub fn article ( self ) -> & ' static str {
77
+ if self . contains ( Self :: ATTR ) { "an" } else { "a" }
78
+ }
79
+ }
80
+
34
81
/// An attribute that is not a macro; e.g., `#[inline]` or `#[rustfmt::skip]`.
35
82
#[ derive( Clone , Copy , PartialEq , Eq , Encodable , Decodable , Hash , Debug , HashStable_Generic ) ]
36
83
pub enum NonMacroAttrKind {
0 commit comments