@@ -29,6 +29,7 @@ use rustc_span::{self, ExpnKind, Pos};
29
29
use rustc_typeck:: hir_ty_to_ty;
30
30
31
31
use std:: collections:: hash_map:: Entry ;
32
+ use std:: collections:: BTreeMap ;
32
33
use std:: default:: Default ;
33
34
use std:: hash:: Hash ;
34
35
use std:: rc:: Rc ;
@@ -60,6 +61,12 @@ impl<T: Clean<U>, U> Clean<Vec<U>> for [T] {
60
61
}
61
62
}
62
63
64
+ impl < K , V : Clean < U > , U > Clean < Vec < U > > for BTreeMap < K , V > {
65
+ fn clean ( & self , cx : & DocContext < ' _ > ) -> Vec < U > {
66
+ self . values ( ) . map ( |x| x. clean ( cx) ) . collect ( )
67
+ }
68
+ }
69
+
63
70
impl < T : Clean < U > , U , V : Idx > Clean < IndexVec < V , U > > for IndexVec < V , T > {
64
71
fn clean ( & self , cx : & DocContext < ' _ > ) -> IndexVec < V , U > {
65
72
self . iter ( ) . map ( |x| x. clean ( cx) ) . collect ( )
@@ -221,6 +228,72 @@ impl Clean<ExternalCrate> for CrateNum {
221
228
}
222
229
}
223
230
231
+ impl Clean < Item > for hir:: Item < ' _ > {
232
+ fn clean ( & self , _cx : & DocContext < ' _ > ) -> Item {
233
+ unimplemented ! ( )
234
+ }
235
+ }
236
+
237
+ impl Clean < Item > for hir:: Crate < ' _ > {
238
+ fn clean ( & self , cx : & DocContext < ' _ > ) -> Item {
239
+ // TODO: use tcx.crate_name instead
240
+ let name = None ;
241
+ let attrs = self . item . attrs . clean ( cx) ;
242
+
243
+ // Get _all_ the items!
244
+ let mut items = self . items . clean ( cx) ;
245
+ items. extend ( self . exported_macros . clean ( cx) ) ;
246
+ items. extend ( self . trait_items . clean ( cx) ) ;
247
+ items. extend ( self . impl_items . clean ( cx) ) ;
248
+ // NOTE: bodies intentionally skipped
249
+
250
+ items. extend ( self . trait_impls . iter ( ) . flat_map ( |( _trait, impls) | {
251
+ impls. into_iter ( ) . map ( |& impl_| cx. tcx . hir ( ) . item ( impl_) . clean ( cx) )
252
+ } ) ) ;
253
+ items. extend ( self . modules . clean ( cx) . into_iter ( ) . flatten ( ) ) ;
254
+ items. extend ( self . proc_macros . iter ( ) . map ( |hir_id| {
255
+ let _def_id = hir_id. owner . local_def_index ;
256
+ // TODO: look how `rustc_metadata::rmeta::encoder` does this
257
+ unimplemented ! ( )
258
+ } ) ) ;
259
+
260
+ // determine if we should display the inner contents or
261
+ // the outer `mod` item for the source code.
262
+ // TODO: for the crate root, I think this should always be `self.item.span`?
263
+ let span = {
264
+ let sm = cx. sess ( ) . source_map ( ) ;
265
+ let outer = sm. lookup_char_pos ( self . item . span . lo ( ) ) ;
266
+ let inner = sm. lookup_char_pos ( self . item . module . inner . lo ( ) ) ;
267
+ if outer. file . start_pos == inner. file . start_pos {
268
+ // mod foo { ... }
269
+ self . item . span
270
+ } else {
271
+ // mod foo; (and a separate SourceFile for the contents)
272
+ self . item . module . inner
273
+ }
274
+ } ;
275
+
276
+ let id = hir:: CRATE_HIR_ID ;
277
+ Item {
278
+ name,
279
+ attrs,
280
+ source : span. clean ( cx) ,
281
+ visibility : Visibility :: Public ,
282
+ stability : cx. stability ( id) ,
283
+ deprecation : cx. deprecation ( id) . clean ( cx) ,
284
+ def_id : cx. tcx . hir ( ) . local_def_id ( id) . to_def_id ( ) ,
285
+ kind : ModuleItem ( Module { is_crate : true , items } ) ,
286
+ }
287
+ }
288
+ }
289
+
290
+ impl Clean < Vec < Item > > for hir:: ModuleItems {
291
+ fn clean ( & self , _cx : & DocContext < ' _ > ) -> Vec < Item > {
292
+ unimplemented ! ( )
293
+ }
294
+ }
295
+
296
+ /*
224
297
impl Clean<Item> for doctree::Module<'_> {
225
298
fn clean(&self, cx: &DocContext<'_>) -> Item {
226
299
// maintain a stack of mod ids, for doc comment path resolution
@@ -276,6 +349,7 @@ impl Clean<Item> for doctree::Module<'_> {
276
349
}
277
350
}
278
351
}
352
+ */
279
353
280
354
impl Clean < Attributes > for [ ast:: Attribute ] {
281
355
fn clean ( & self , cx : & DocContext < ' _ > ) -> Attributes {
@@ -718,7 +792,6 @@ impl Clean<Generics> for hir::Generics<'_> {
718
792
impl < ' a , ' tcx > Clean < Generics > for ( & ' a ty:: Generics , ty:: GenericPredicates < ' tcx > ) {
719
793
fn clean ( & self , cx : & DocContext < ' _ > ) -> Generics {
720
794
use self :: WherePredicate as WP ;
721
- use std:: collections:: BTreeMap ;
722
795
723
796
let ( gens, preds) = * self ;
724
797
@@ -2280,24 +2353,9 @@ impl Clean<Item> for doctree::ForeignItem<'_> {
2280
2353
}
2281
2354
}
2282
2355
2283
- impl Clean < Item > for doctree:: Macro {
2284
- fn clean ( & self , cx : & DocContext < ' _ > ) -> Item {
2285
- Item :: from_def_id_and_parts (
2286
- self . def_id ,
2287
- Some ( self . name ) ,
2288
- MacroItem ( Macro {
2289
- source : format ! (
2290
- "macro_rules! {} {{\n {}}}" ,
2291
- self . name,
2292
- self . matchers
2293
- . iter( )
2294
- . map( |span| { format!( " {} => {{ ... }};\n " , span. to_src( cx) ) } )
2295
- . collect:: <String >( )
2296
- ) ,
2297
- imported_from : self . imported_from . clean ( cx) ,
2298
- } ) ,
2299
- cx,
2300
- )
2356
+ impl Clean < Item > for hir:: MacroDef < ' _ > {
2357
+ fn clean ( & self , _cx : & DocContext < ' _ > ) -> Item {
2358
+ unimplemented ! ( )
2301
2359
}
2302
2360
}
2303
2361
0 commit comments