File tree Expand file tree Collapse file tree 1 file changed +21
-14
lines changed Expand file tree Collapse file tree 1 file changed +21
-14
lines changed Original file line number Diff line number Diff line change @@ -2320,22 +2320,29 @@ impl Clean<Item> for (&hir::MacroDef<'_>, Option<Ident>) {
2320
2320
let tts = item. ast . body . inner_tokens ( ) . trees ( ) . collect :: < Vec < _ > > ( ) ;
2321
2321
// Extract the spans of all matchers. They represent the "interface" of the macro.
2322
2322
let matchers = tts. chunks ( 4 ) . map ( |arm| arm[ 0 ] . span ( ) ) . collect :: < Vec < _ > > ( ) ;
2323
+ let source = if item. ast . macro_rules {
2324
+ format ! (
2325
+ "macro_rules! {} {{\n {}}}" ,
2326
+ name,
2327
+ matchers
2328
+ . iter( )
2329
+ . map( |span| { format!( " {} => {{ ... }};\n " , span. to_src( cx) ) } )
2330
+ . collect:: <String >( ) ,
2331
+ )
2332
+ } else {
2333
+ // This code currently assumes that there will only be one or zero matchers, as syntax
2334
+ // for multiple is not currently defined.
2335
+ format ! (
2336
+ "pub macro {}({}) {{\n \t ...\n }}" ,
2337
+ name,
2338
+ matchers. iter( ) . map( |span| span. to_src( cx) ) . collect:: <String >( ) ,
2339
+ )
2340
+ } ;
2323
2341
2324
- Item :: from_def_id_and_parts (
2325
- cx . tcx . hir ( ) . local_def_id ( item. hir_id ) . to_def_id ( ) ,
2342
+ Item :: from_hir_id_and_parts (
2343
+ item. hir_id ,
2326
2344
Some ( name. clean ( cx) ) ,
2327
- MacroItem ( Macro {
2328
- // FIXME(#76761): Make this respect `macro_rules!` vs `pub macro`
2329
- source : format ! (
2330
- "macro_rules! {} {{\n {}}}" ,
2331
- name,
2332
- matchers
2333
- . iter( )
2334
- . map( |span| { format!( " {} => {{ ... }};\n " , span. to_src( cx) ) } )
2335
- . collect:: <String >( ) ,
2336
- ) ,
2337
- imported_from : None ,
2338
- } ) ,
2345
+ MacroItem ( Macro { source, imported_from : None } ) ,
2339
2346
cx,
2340
2347
)
2341
2348
}
You can’t perform that action at this time.
0 commit comments