@@ -157,6 +157,7 @@ pub struct Cache {
157
157
priv parent_stack : ~[ ast:: NodeId ] ,
158
158
priv search_index : ~[ IndexItem ] ,
159
159
priv privmod : bool ,
160
+ priv public_items : HashSet < ast:: NodeId > ,
160
161
}
161
162
162
163
/// Helper struct to render all source code to HTML pages
@@ -231,18 +232,23 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
231
232
}
232
233
233
234
// Crawl the crate to build various caches used for the output
234
- let mut cache = Cache {
235
- impls : HashMap :: new ( ) ,
236
- typarams : HashMap :: new ( ) ,
237
- paths : HashMap :: new ( ) ,
238
- traits : HashMap :: new ( ) ,
239
- implementors : HashMap :: new ( ) ,
240
- stack : ~[ ] ,
241
- parent_stack : ~[ ] ,
242
- search_index : ~[ ] ,
243
- extern_locations : HashMap :: new ( ) ,
244
- privmod : false ,
245
- } ;
235
+ let mut cache = local_data:: get ( :: analysiskey, |analysis| {
236
+ let public_items = analysis. map ( |a| a. public_items . clone ( ) ) ;
237
+ let public_items = public_items. unwrap_or ( HashSet :: new ( ) ) ;
238
+ Cache {
239
+ impls : HashMap :: new ( ) ,
240
+ typarams : HashMap :: new ( ) ,
241
+ paths : HashMap :: new ( ) ,
242
+ traits : HashMap :: new ( ) ,
243
+ implementors : HashMap :: new ( ) ,
244
+ stack : ~[ ] ,
245
+ parent_stack : ~[ ] ,
246
+ search_index : ~[ ] ,
247
+ extern_locations : HashMap :: new ( ) ,
248
+ privmod : false ,
249
+ public_items : public_items,
250
+ }
251
+ } ) ;
246
252
cache. stack . push ( krate. name . clone ( ) ) ;
247
253
krate = cache. fold_crate ( krate) ;
248
254
@@ -305,7 +311,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
305
311
krate = folder. fold_crate ( krate) ;
306
312
}
307
313
308
- for ( & n , e) in krate. externs . iter ( ) {
314
+ for & ( n , ref e) in krate. externs . iter ( ) {
309
315
cache. extern_locations . insert ( n, extern_location ( e, & cx. dst ) ) ;
310
316
}
311
317
@@ -565,8 +571,24 @@ impl DocFolder for Cache {
565
571
clean:: StructItem ( ..) | clean:: EnumItem ( ..) |
566
572
clean:: TypedefItem ( ..) | clean:: TraitItem ( ..) |
567
573
clean:: FunctionItem ( ..) | clean:: ModuleItem ( ..) |
568
- clean:: ForeignFunctionItem ( ..) | clean:: VariantItem ( ..) => {
569
- self . paths . insert ( item. id , ( self . stack . clone ( ) , shortty ( & item) ) ) ;
574
+ clean:: ForeignFunctionItem ( ..) => {
575
+ // Reexported items mean that the same id can show up twice in
576
+ // the rustdoc ast that we're looking at. We know, however, that
577
+ // a reexported item doesn't show up in the `public_items` map,
578
+ // so we can skip inserting into the paths map if there was
579
+ // already an entry present and we're not a public item.
580
+ if !self . paths . contains_key ( & item. id ) ||
581
+ self . public_items . contains ( & item. id ) {
582
+ self . paths . insert ( item. id ,
583
+ ( self . stack . clone ( ) , shortty ( & item) ) ) ;
584
+ }
585
+ }
586
+ // link variants to their parent enum because pages aren't emitted
587
+ // for each variant
588
+ clean:: VariantItem ( ..) => {
589
+ let mut stack = self . stack . clone ( ) ;
590
+ stack. pop ( ) ;
591
+ self . paths . insert ( item. id , ( stack, "enum" ) ) ;
570
592
}
571
593
_ => { }
572
594
}
@@ -791,6 +813,7 @@ fn shortty(item: &clean::Item) -> &'static str {
791
813
clean:: VariantItem ( ..) => "variant" ,
792
814
clean:: ForeignFunctionItem ( ..) => "ffi" ,
793
815
clean:: ForeignStaticItem ( ..) => "ffs" ,
816
+ clean:: MacroItem ( ..) => "macro" ,
794
817
}
795
818
}
796
819
@@ -869,6 +892,7 @@ impl<'a> fmt::Show for Item<'a> {
869
892
clean:: StructItem ( ref s) => item_struct ( fmt. buf , self . item , s) ,
870
893
clean:: EnumItem ( ref e) => item_enum ( fmt. buf , self . item , e) ,
871
894
clean:: TypedefItem ( ref t) => item_typedef ( fmt. buf , self . item , t) ,
895
+ clean:: MacroItem ( ref m) => item_macro ( fmt. buf , self . item , m) ,
872
896
_ => Ok ( ( ) )
873
897
}
874
898
}
@@ -937,6 +961,8 @@ fn item_module(w: &mut Writer, cx: &Context,
937
961
( _, & clean:: ViewItemItem ( ..) ) => Greater ,
938
962
( & clean:: ModuleItem ( ..) , _) => Less ,
939
963
( _, & clean:: ModuleItem ( ..) ) => Greater ,
964
+ ( & clean:: MacroItem ( ..) , _) => Less ,
965
+ ( _, & clean:: MacroItem ( ..) ) => Greater ,
940
966
( & clean:: StructItem ( ..) , _) => Less ,
941
967
( _, & clean:: StructItem ( ..) ) => Greater ,
942
968
( & clean:: EnumItem ( ..) , _) => Less ,
@@ -987,6 +1013,7 @@ fn item_module(w: &mut Writer, cx: &Context,
987
1013
clean:: VariantItem ( ..) => "Variants" ,
988
1014
clean:: ForeignFunctionItem ( ..) => "Foreign Functions" ,
989
1015
clean:: ForeignStaticItem ( ..) => "Foreign Statics" ,
1016
+ clean:: MacroItem ( ..) => "Macros" ,
990
1017
} ) ) ;
991
1018
}
992
1019
@@ -1099,15 +1126,15 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
1099
1126
if_ok ! ( write!( w, "\\ {\n " ) ) ;
1100
1127
for m in required. iter ( ) {
1101
1128
if_ok ! ( write!( w, " " ) ) ;
1102
- if_ok ! ( render_method( w, m. item( ) , true ) ) ;
1129
+ if_ok ! ( render_method( w, m. item( ) ) ) ;
1103
1130
if_ok ! ( write!( w, ";\n " ) ) ;
1104
1131
}
1105
1132
if required. len ( ) > 0 && provided. len ( ) > 0 {
1106
1133
if_ok ! ( w. write( "\n " . as_bytes( ) ) ) ;
1107
1134
}
1108
1135
for m in provided. iter ( ) {
1109
1136
if_ok ! ( write!( w, " " ) ) ;
1110
- if_ok ! ( render_method( w, m. item( ) , true ) ) ;
1137
+ if_ok ! ( render_method( w, m. item( ) ) ) ;
1111
1138
if_ok ! ( write!( w, " \\ { ... \\ }\n " ) ) ;
1112
1139
}
1113
1140
if_ok ! ( write!( w, "\\ }" ) ) ;
@@ -1121,7 +1148,7 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
1121
1148
if_ok ! ( write!( w, "<h3 id='{}.{}' class='method'><code>" ,
1122
1149
shortty( m. item( ) ) ,
1123
1150
* m. item( ) . name. get_ref( ) ) ) ;
1124
- if_ok ! ( render_method( w, m. item( ) , false ) ) ;
1151
+ if_ok ! ( render_method( w, m. item( ) ) ) ;
1125
1152
if_ok ! ( write!( w, "</code></h3>" ) ) ;
1126
1153
if_ok ! ( document( w, m. item( ) ) ) ;
1127
1154
Ok ( ( ) )
@@ -1176,32 +1203,27 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
1176
1203
} )
1177
1204
}
1178
1205
1179
- fn render_method ( w : & mut Writer , meth : & clean:: Item ,
1180
- withlink : bool ) -> fmt:: Result {
1206
+ fn render_method ( w : & mut Writer , meth : & clean:: Item ) -> fmt:: Result {
1181
1207
fn fun ( w : & mut Writer , it : & clean:: Item , purity : ast:: Purity ,
1182
- g : & clean:: Generics , selfty : & clean:: SelfTy , d : & clean:: FnDecl ,
1183
- withlink : bool ) -> fmt:: Result {
1184
- write ! ( w, "{}fn {withlink, select,
1185
- true{<a href='\\ #{ty}.{name}'
1186
- class='fnname'>{name}</a>}
1187
- other{<span class='fnname'>{name}</span>}
1188
- }{generics}{decl}" ,
1208
+ g : & clean:: Generics , selfty : & clean:: SelfTy ,
1209
+ d : & clean:: FnDecl ) -> fmt:: Result {
1210
+ write ! ( w, "{}fn <a href='\\ #{ty}.{name}' class='fnname'>{name}</a>\
1211
+ {generics}{decl}",
1189
1212
match purity {
1190
1213
ast:: UnsafeFn => "unsafe " ,
1191
1214
_ => "" ,
1192
1215
} ,
1193
1216
ty = shortty( it) ,
1194
1217
name = it. name. get_ref( ) . as_slice( ) ,
1195
1218
generics = * g,
1196
- decl = Method ( selfty, d) ,
1197
- withlink = if withlink { "true" } else { "false" } )
1219
+ decl = Method ( selfty, d) )
1198
1220
}
1199
1221
match meth. inner {
1200
1222
clean:: TyMethodItem ( ref m) => {
1201
- fun ( w, meth, m. purity , & m. generics , & m. self_ , & m. decl , withlink )
1223
+ fun ( w, meth, m. purity , & m. generics , & m. self_ , & m. decl )
1202
1224
}
1203
1225
clean:: MethodItem ( ref m) => {
1204
- fun ( w, meth, m. purity , & m. generics , & m. self_ , & m. decl , withlink )
1226
+ fun ( w, meth, m. purity , & m. generics , & m. self_ , & m. decl )
1205
1227
}
1206
1228
_ => unreachable ! ( )
1207
1229
}
@@ -1432,7 +1454,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
1432
1454
fn docmeth ( w : & mut Writer , item : & clean:: Item ) -> io:: IoResult < bool > {
1433
1455
if_ok ! ( write!( w, "<h4 id='method.{}' class='method'><code>" ,
1434
1456
* item. name. get_ref( ) ) ) ;
1435
- if_ok ! ( render_method( w, item, false ) ) ;
1457
+ if_ok ! ( render_method( w, item) ) ;
1436
1458
if_ok ! ( write!( w, "</code></h4>\n " ) ) ;
1437
1459
match item. doc_value ( ) {
1438
1460
Some ( s) => {
@@ -1609,3 +1631,9 @@ impl<'a> fmt::Show for Source<'a> {
1609
1631
Ok ( ( ) )
1610
1632
}
1611
1633
}
1634
+
1635
+ fn item_macro ( w : & mut Writer , it : & clean:: Item ,
1636
+ t : & clean:: Macro ) -> fmt:: Result {
1637
+ if_ok ! ( write!( w, "<pre class='macro'>{}</pre>" , t. source) ) ;
1638
+ document ( w, it)
1639
+ }
0 commit comments