@@ -18,8 +18,7 @@ pub use self::TypeKind::*;
18
18
pub use self :: StructField :: * ;
19
19
pub use self :: VariantKind :: * ;
20
20
pub use self :: Mutability :: * ;
21
- pub use self :: ViewItemInner :: * ;
22
- pub use self :: ViewPath :: * ;
21
+ pub use self :: Import :: * ;
23
22
pub use self :: ItemEnum :: * ;
24
23
pub use self :: Attribute :: * ;
25
24
pub use self :: TyParamBound :: * ;
@@ -309,6 +308,8 @@ impl Item {
309
308
310
309
#[ derive( Clone , RustcEncodable , RustcDecodable ) ]
311
310
pub enum ItemEnum {
311
+ ExternCrateItem ( String , Option < String > ) ,
312
+ ImportItem ( Import ) ,
312
313
StructItem ( Struct ) ,
313
314
EnumItem ( Enum ) ,
314
315
FunctionItem ( Function ) ,
@@ -318,8 +319,6 @@ pub enum ItemEnum {
318
319
ConstantItem ( Constant ) ,
319
320
TraitItem ( Trait ) ,
320
321
ImplItem ( Impl ) ,
321
- /// `use` and `extern crate`
322
- ViewItemItem ( ViewItem ) ,
323
322
/// A method signature only. Used for required methods in traits (ie,
324
323
/// non-default-methods).
325
324
TyMethodItem ( TyMethod ) ,
@@ -349,27 +348,21 @@ impl Clean<Item> for doctree::Module {
349
348
} else {
350
349
"" . to_string ( )
351
350
} ;
352
- let mut foreigns = Vec :: new ( ) ;
353
- for subforeigns in self . foreigns . clean ( cx) . into_iter ( ) {
354
- for foreign in subforeigns. into_iter ( ) {
355
- foreigns. push ( foreign)
356
- }
357
- }
358
- let items: Vec < Vec < Item > > = vec ! (
359
- self . structs. clean( cx) ,
360
- self . enums. clean( cx) ,
361
- self . fns. clean( cx) ,
362
- foreigns,
363
- self . mods. clean( cx) ,
364
- self . typedefs. clean( cx) ,
365
- self . statics. clean( cx) ,
366
- self . constants. clean( cx) ,
367
- self . traits. clean( cx) ,
368
- self . impls. clean( cx) ,
369
- self . view_items. clean( cx) . into_iter( )
370
- . flat_map( |s| s. into_iter( ) ) . collect( ) ,
371
- self . macros. clean( cx) ,
372
- ) ;
351
+ let items: Vec < Item > =
352
+ self . extern_crates . iter ( ) . map ( |x| x. clean ( cx) )
353
+ . chain ( self . imports . iter ( ) . flat_map ( |x| x. clean ( cx) . into_iter ( ) ) )
354
+ . chain ( self . structs . iter ( ) . map ( |x| x. clean ( cx) ) )
355
+ . chain ( self . enums . iter ( ) . map ( |x| x. clean ( cx) ) )
356
+ . chain ( self . fns . iter ( ) . map ( |x| x. clean ( cx) ) )
357
+ . chain ( self . foreigns . iter ( ) . flat_map ( |x| x. clean ( cx) . into_iter ( ) ) )
358
+ . chain ( self . mods . iter ( ) . map ( |x| x. clean ( cx) ) )
359
+ . chain ( self . typedefs . iter ( ) . map ( |x| x. clean ( cx) ) )
360
+ . chain ( self . statics . iter ( ) . map ( |x| x. clean ( cx) ) )
361
+ . chain ( self . constants . iter ( ) . map ( |x| x. clean ( cx) ) )
362
+ . chain ( self . traits . iter ( ) . map ( |x| x. clean ( cx) ) )
363
+ . chain ( self . impls . iter ( ) . map ( |x| x. clean ( cx) ) )
364
+ . chain ( self . macros . iter ( ) . map ( |x| x. clean ( cx) ) )
365
+ . collect ( ) ;
373
366
374
367
// determine if we should display the inner contents or
375
368
// the outer `mod` item for the source code.
@@ -395,9 +388,7 @@ impl Clean<Item> for doctree::Module {
395
388
def_id : ast_util:: local_def ( self . id ) ,
396
389
inner : ModuleItem ( Module {
397
390
is_crate : self . is_crate ,
398
- items : items. iter ( )
399
- . flat_map ( |x| x. iter ( ) . map ( |x| ( * x) . clone ( ) ) )
400
- . collect ( ) ,
391
+ items : items
401
392
} )
402
393
}
403
394
}
@@ -2120,12 +2111,21 @@ impl Clean<Item> for doctree::Impl {
2120
2111
}
2121
2112
}
2122
2113
2123
- #[ derive( Clone , RustcEncodable , RustcDecodable ) ]
2124
- pub struct ViewItem {
2125
- pub inner : ViewItemInner ,
2114
+ impl Clean < Item > for doctree:: ExternCrate {
2115
+ fn clean ( & self , cx : & DocContext ) -> Item {
2116
+ Item {
2117
+ name : None ,
2118
+ attrs : self . attrs . clean ( cx) ,
2119
+ source : self . whence . clean ( cx) ,
2120
+ def_id : ast_util:: local_def ( 0 ) ,
2121
+ visibility : self . vis . clean ( cx) ,
2122
+ stability : None ,
2123
+ inner : ExternCrateItem ( self . name . clean ( cx) , self . path . clone ( ) )
2124
+ }
2125
+ }
2126
2126
}
2127
2127
2128
- impl Clean < Vec < Item > > for ast :: ViewItem {
2128
+ impl Clean < Vec < Item > > for doctree :: Import {
2129
2129
fn clean ( & self , cx : & DocContext ) -> Vec < Item > {
2130
2130
// We consider inlining the documentation of `pub use` statements, but we
2131
2131
// forcefully don't inline if this is not public or if the
@@ -2136,81 +2136,63 @@ impl Clean<Vec<Item>> for ast::ViewItem {
2136
2136
None => false ,
2137
2137
}
2138
2138
} ) ;
2139
- let convert = |& : node: & ast:: ViewItem_ | {
2140
- Item {
2141
- name : None ,
2142
- attrs : self . attrs . clean ( cx) ,
2143
- source : self . span . clean ( cx) ,
2144
- def_id : ast_util:: local_def ( 0 ) ,
2145
- visibility : self . vis . clean ( cx) ,
2146
- stability : None ,
2147
- inner : ViewItemItem ( ViewItem { inner : node. clean ( cx) } ) ,
2139
+ let ( mut ret, inner) = match self . node {
2140
+ ast:: ViewPathGlob ( ref p) => {
2141
+ ( vec ! [ ] , GlobImport ( resolve_use_source ( cx, p. clean ( cx) , self . id ) ) )
2148
2142
}
2149
- } ;
2150
- let mut ret = Vec :: new ( ) ;
2151
- match self . node {
2152
- ast:: ViewItemUse ( ref path) if !denied => {
2153
- match path. node {
2154
- ast:: ViewPathGlob ( ..) => ret. push ( convert ( & self . node ) ) ,
2155
- ast:: ViewPathList ( ref a, ref list, ref b) => {
2156
- // Attempt to inline all reexported items, but be sure
2157
- // to keep any non-inlineable reexports so they can be
2158
- // listed in the documentation.
2159
- let remaining = list. iter ( ) . filter ( |path| {
2160
- match inline:: try_inline ( cx, path. node . id ( ) , None ) {
2161
- Some ( items) => {
2162
- ret. extend ( items. into_iter ( ) ) ; false
2163
- }
2164
- None => true ,
2143
+ ast:: ViewPathList ( ref p, ref list) => {
2144
+ // Attempt to inline all reexported items, but be sure
2145
+ // to keep any non-inlineable reexports so they can be
2146
+ // listed in the documentation.
2147
+ let mut ret = vec ! [ ] ;
2148
+ let remaining = if !denied {
2149
+ let mut remaining = vec ! [ ] ;
2150
+ for path in list. iter ( ) {
2151
+ match inline:: try_inline ( cx, path. node . id ( ) , None ) {
2152
+ Some ( items) => {
2153
+ ret. extend ( items. into_iter ( ) ) ;
2154
+ }
2155
+ None => {
2156
+ remaining. push ( path. clean ( cx) ) ;
2165
2157
}
2166
- } ) . map ( |a| a. clone ( ) ) . collect :: < Vec < ast:: PathListItem > > ( ) ;
2167
- if remaining. len ( ) > 0 {
2168
- let path = ast:: ViewPathList ( a. clone ( ) ,
2169
- remaining,
2170
- b. clone ( ) ) ;
2171
- let path = syntax:: codemap:: dummy_spanned ( path) ;
2172
- ret. push ( convert ( & ast:: ViewItemUse ( P ( path) ) ) ) ;
2173
- }
2174
- }
2175
- ast:: ViewPathSimple ( ident, _, id) => {
2176
- match inline:: try_inline ( cx, id, Some ( ident) ) {
2177
- Some ( items) => ret. extend ( items. into_iter ( ) ) ,
2178
- None => ret. push ( convert ( & self . node ) ) ,
2179
2158
}
2180
2159
}
2181
- }
2182
- }
2183
- ref n => ret. push ( convert ( n) ) ,
2184
- }
2185
- return ret;
2186
- }
2187
- }
2188
-
2189
- #[ derive( Clone , RustcEncodable , RustcDecodable ) ]
2190
- pub enum ViewItemInner {
2191
- ExternCrate ( String , Option < String > , ast:: NodeId ) ,
2192
- Import ( ViewPath )
2193
- }
2194
-
2195
- impl Clean < ViewItemInner > for ast:: ViewItem_ {
2196
- fn clean ( & self , cx : & DocContext ) -> ViewItemInner {
2197
- match self {
2198
- & ast:: ViewItemExternCrate ( ref i, ref p, ref id) => {
2199
- let string = match * p {
2200
- None => None ,
2201
- Some ( ( ref x, _) ) => Some ( x. get ( ) . to_string ( ) ) ,
2160
+ remaining
2161
+ } else {
2162
+ list. clean ( cx)
2202
2163
} ;
2203
- ExternCrate ( i. clean ( cx) , string, * id)
2164
+ if remaining. is_empty ( ) {
2165
+ return ret;
2166
+ }
2167
+ ( ret, ImportList ( resolve_use_source ( cx, p. clean ( cx) , self . id ) ,
2168
+ remaining) )
2204
2169
}
2205
- & ast:: ViewItemUse ( ref vp) => {
2206
- Import ( vp. clean ( cx) )
2170
+ ast:: ViewPathSimple ( i, ref p) => {
2171
+ if !denied {
2172
+ match inline:: try_inline ( cx, self . id , Some ( i) ) {
2173
+ Some ( items) => return items,
2174
+ None => { }
2175
+ }
2176
+ }
2177
+ ( vec ! [ ] , SimpleImport ( i. clean ( cx) ,
2178
+ resolve_use_source ( cx, p. clean ( cx) , self . id ) ) )
2207
2179
}
2208
- }
2180
+ } ;
2181
+ ret. push ( Item {
2182
+ name : None ,
2183
+ attrs : self . attrs . clean ( cx) ,
2184
+ source : self . whence . clean ( cx) ,
2185
+ def_id : ast_util:: local_def ( 0 ) ,
2186
+ visibility : self . vis . clean ( cx) ,
2187
+ stability : None ,
2188
+ inner : ImportItem ( inner)
2189
+ } ) ;
2190
+ ret
2209
2191
}
2210
2192
}
2211
2193
2212
2194
#[ derive( Clone , RustcEncodable , RustcDecodable ) ]
2213
- pub enum ViewPath {
2195
+ pub enum Import {
2214
2196
// use source as str;
2215
2197
SimpleImport ( String , ImportSource ) ,
2216
2198
// use source::*;
@@ -2225,21 +2207,6 @@ pub struct ImportSource {
2225
2207
pub did : Option < ast:: DefId > ,
2226
2208
}
2227
2209
2228
- impl Clean < ViewPath > for ast:: ViewPath {
2229
- fn clean ( & self , cx : & DocContext ) -> ViewPath {
2230
- match self . node {
2231
- ast:: ViewPathSimple ( ref i, ref p, id) =>
2232
- SimpleImport ( i. clean ( cx) , resolve_use_source ( cx, p. clean ( cx) , id) ) ,
2233
- ast:: ViewPathGlob ( ref p, id) =>
2234
- GlobImport ( resolve_use_source ( cx, p. clean ( cx) , id) ) ,
2235
- ast:: ViewPathList ( ref p, ref pl, id) => {
2236
- ImportList ( resolve_use_source ( cx, p. clean ( cx) , id) ,
2237
- pl. clean ( cx) )
2238
- }
2239
- }
2240
- }
2241
- }
2242
-
2243
2210
#[ derive( Clone , RustcEncodable , RustcDecodable ) ]
2244
2211
pub struct ViewListIdent {
2245
2212
pub name : String ,
0 commit comments