This repository was archived by the owner on May 28, 2025. It is now read-only.
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>) {
23202320 let tts = item. ast . body . inner_tokens ( ) . trees ( ) . collect :: < Vec < _ > > ( ) ;
23212321 // Extract the spans of all matchers. They represent the "interface" of the macro.
23222322 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+ } ;
23232341
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 ,
23262344 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 } ) ,
23392346 cx,
23402347 )
23412348 }
You can’t perform that action at this time.
0 commit comments