File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -2354,8 +2354,30 @@ impl Clean<Item> for doctree::ForeignItem<'_> {
2354
2354
}
2355
2355
2356
2356
impl Clean < Item > for hir:: MacroDef < ' _ > {
2357
- fn clean ( & self , _cx : & DocContext < ' _ > ) -> Item {
2358
- unimplemented ! ( )
2357
+ fn clean ( & self , cx : & DocContext < ' _ > ) -> Item {
2358
+ let tts: Vec < _ > = self . ast . body . inner_tokens ( ) . trees ( ) . collect ( ) ;
2359
+ // Extract the spans of all matchers. They represent the "interface" of the macro.
2360
+ let matchers = tts. chunks ( 4 ) . map ( |arm| arm[ 0 ] . span ( ) ) ;
2361
+
2362
+ Item {
2363
+ name : Some ( self . ident . name . to_string ( ) ) , // TODO: this should store a Symbol
2364
+ attrs : self . attrs . clean ( cx) ,
2365
+ source : self . span . clean ( cx) ,
2366
+ visibility : Public ,
2367
+ stability : cx. stability ( self . hir_id ) ,
2368
+ deprecation : cx. deprecation ( self . hir_id ) . clean ( cx) ,
2369
+ def_id : cx. tcx . hir ( ) . local_def_id ( self . hir_id ) . to_def_id ( ) ,
2370
+ kind : MacroItem ( Macro {
2371
+ source : format ! (
2372
+ "macro_rules! {} {{\n {}}}" ,
2373
+ self . ident. name,
2374
+ matchers
2375
+ . map( |span| { format!( " {} => {{ ... }};\n " , span. to_src( cx) ) } )
2376
+ . collect:: <String >( )
2377
+ ) ,
2378
+ imported_from : None ,
2379
+ } ) ,
2380
+ }
2359
2381
}
2360
2382
}
2361
2383
You can’t perform that action at this time.
0 commit comments