@@ -22,21 +22,16 @@ struct ProcMacroDerive {
22
22
attrs : Vec < Symbol > ,
23
23
}
24
24
25
- enum ProcMacroDefType {
26
- Attr ,
27
- Bang ,
28
- }
29
-
30
25
struct ProcMacroDef {
31
26
id : NodeId ,
32
27
function_name : Ident ,
33
28
span : Span ,
34
- def_type : ProcMacroDefType ,
35
29
}
36
30
37
31
enum ProcMacro {
38
32
Derive ( ProcMacroDerive ) ,
39
- Def ( ProcMacroDef ) ,
33
+ Attr ( ProcMacroDef ) ,
34
+ Bang ( ProcMacroDef ) ,
40
35
}
41
36
42
37
struct CollectProcMacros < ' a > {
@@ -128,11 +123,10 @@ impl<'a> CollectProcMacros<'a> {
128
123
129
124
fn collect_attr_proc_macro ( & mut self , item : & ' a ast:: Item ) {
130
125
if self . in_root && item. vis . kind . is_pub ( ) {
131
- self . macros . push ( ProcMacro :: Def ( ProcMacroDef {
126
+ self . macros . push ( ProcMacro :: Attr ( ProcMacroDef {
132
127
id : item. id ,
133
128
span : item. span ,
134
129
function_name : item. ident ,
135
- def_type : ProcMacroDefType :: Attr ,
136
130
} ) ) ;
137
131
} else {
138
132
let msg = if !self . in_root {
@@ -147,11 +141,10 @@ impl<'a> CollectProcMacros<'a> {
147
141
148
142
fn collect_bang_proc_macro ( & mut self , item : & ' a ast:: Item ) {
149
143
if self . in_root && item. vis . kind . is_pub ( ) {
150
- self . macros . push ( ProcMacro :: Def ( ProcMacroDef {
144
+ self . macros . push ( ProcMacro :: Bang ( ProcMacroDef {
151
145
id : item. id ,
152
146
span : item. span ,
153
147
function_name : item. ident ,
154
- def_type : ProcMacroDefType :: Bang ,
155
148
} ) ) ;
156
149
} else {
157
150
let msg = if !self . in_root {
@@ -308,6 +301,17 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
308
301
let proc_macro_ty_method_path = |cx : & ExtCtxt < ' _ > , method| {
309
302
cx. expr_path ( cx. path ( span, vec ! [ proc_macro, bridge, client, proc_macro_ty, method] ) )
310
303
} ;
304
+ let attr_or_bang = |cx : & mut ExtCtxt < ' _ > , ca : & ProcMacroDef , ident| {
305
+ cx. resolver . declare_proc_macro ( ca. id ) ;
306
+ cx. expr_call (
307
+ span,
308
+ proc_macro_ty_method_path ( cx, ident) ,
309
+ vec ! [
310
+ cx. expr_str( ca. span, ca. function_name. name) ,
311
+ local_path( cx, ca. span, ca. function_name) ,
312
+ ] ,
313
+ )
314
+ } ;
311
315
macros
312
316
. iter ( )
313
317
. map ( |m| match m {
@@ -329,22 +333,8 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
329
333
] ,
330
334
)
331
335
}
332
- ProcMacro :: Def ( ca) => {
333
- cx. resolver . declare_proc_macro ( ca. id ) ;
334
- let ident = match ca. def_type {
335
- ProcMacroDefType :: Attr => attr,
336
- ProcMacroDefType :: Bang => bang,
337
- } ;
338
-
339
- cx. expr_call (
340
- span,
341
- proc_macro_ty_method_path ( cx, ident) ,
342
- vec ! [
343
- cx. expr_str( ca. span, ca. function_name. name) ,
344
- local_path( cx, ca. span, ca. function_name) ,
345
- ] ,
346
- )
347
- }
336
+ ProcMacro :: Attr ( ca) => attr_or_bang ( cx, & ca, attr) ,
337
+ ProcMacro :: Bang ( ca) => attr_or_bang ( cx, & ca, bang) ,
348
338
} )
349
339
. collect ( )
350
340
} ;
0 commit comments