@@ -22,21 +22,16 @@ struct ProcMacroDerive {
2222 attrs : Vec < Symbol > ,
2323}
2424
25- enum ProcMacroDefType {
26- Attr ,
27- Bang ,
28- }
29-
3025struct ProcMacroDef {
3126 id : NodeId ,
3227 function_name : Ident ,
3328 span : Span ,
34- def_type : ProcMacroDefType ,
3529}
3630
3731enum ProcMacro {
3832 Derive ( ProcMacroDerive ) ,
39- Def ( ProcMacroDef ) ,
33+ Attr ( ProcMacroDef ) ,
34+ Bang ( ProcMacroDef ) ,
4035}
4136
4237struct CollectProcMacros < ' a > {
@@ -128,11 +123,10 @@ impl<'a> CollectProcMacros<'a> {
128123
129124 fn collect_attr_proc_macro ( & mut self , item : & ' a ast:: Item ) {
130125 if self . in_root && item. vis . kind . is_pub ( ) {
131- self . macros . push ( ProcMacro :: Def ( ProcMacroDef {
126+ self . macros . push ( ProcMacro :: Attr ( ProcMacroDef {
132127 id : item. id ,
133128 span : item. span ,
134129 function_name : item. ident ,
135- def_type : ProcMacroDefType :: Attr ,
136130 } ) ) ;
137131 } else {
138132 let msg = if !self . in_root {
@@ -147,11 +141,10 @@ impl<'a> CollectProcMacros<'a> {
147141
148142 fn collect_bang_proc_macro ( & mut self , item : & ' a ast:: Item ) {
149143 if self . in_root && item. vis . kind . is_pub ( ) {
150- self . macros . push ( ProcMacro :: Def ( ProcMacroDef {
144+ self . macros . push ( ProcMacro :: Bang ( ProcMacroDef {
151145 id : item. id ,
152146 span : item. span ,
153147 function_name : item. ident ,
154- def_type : ProcMacroDefType :: Bang ,
155148 } ) ) ;
156149 } else {
157150 let msg = if !self . in_root {
@@ -308,6 +301,17 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
308301 let proc_macro_ty_method_path = |cx : & ExtCtxt < ' _ > , method| {
309302 cx. expr_path ( cx. path ( span, vec ! [ proc_macro, bridge, client, proc_macro_ty, method] ) )
310303 } ;
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+ } ;
311315 macros
312316 . iter ( )
313317 . map ( |m| match m {
@@ -329,22 +333,8 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> {
329333 ] ,
330334 )
331335 }
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) ,
348338 } )
349339 . collect ( )
350340 } ;
0 commit comments