@@ -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 :: * ;
@@ -303,6 +302,8 @@ impl Item {
303
302
304
303
#[ derive( Clone , RustcEncodable , RustcDecodable ) ]
305
304
pub enum ItemEnum {
305
+ ExternCrateItem ( String , Option < String > ) ,
306
+ ImportItem ( Import ) ,
306
307
StructItem ( Struct ) ,
307
308
EnumItem ( Enum ) ,
308
309
FunctionItem ( Function ) ,
@@ -312,8 +313,6 @@ pub enum ItemEnum {
312
313
ConstantItem ( Constant ) ,
313
314
TraitItem ( Trait ) ,
314
315
ImplItem ( Impl ) ,
315
- /// `use` and `extern crate`
316
- ViewItemItem ( ViewItem ) ,
317
316
/// A method signature only. Used for required methods in traits (ie,
318
317
/// non-default-methods).
319
318
TyMethodItem ( TyMethod ) ,
@@ -343,27 +342,21 @@ impl Clean<Item> for doctree::Module {
343
342
} else {
344
343
"" . to_string ( )
345
344
} ;
346
- let mut foreigns = Vec :: new ( ) ;
347
- for subforeigns in self . foreigns . clean ( cx) . into_iter ( ) {
348
- for foreign in subforeigns. into_iter ( ) {
349
- foreigns. push ( foreign)
350
- }
351
- }
352
- let items: Vec < Vec < Item > > = vec ! (
353
- self . structs. clean( cx) ,
354
- self . enums. clean( cx) ,
355
- self . fns. clean( cx) ,
356
- foreigns,
357
- self . mods. clean( cx) ,
358
- self . typedefs. clean( cx) ,
359
- self . statics. clean( cx) ,
360
- self . constants. clean( cx) ,
361
- self . traits. clean( cx) ,
362
- self . impls. clean( cx) ,
363
- self . view_items. clean( cx) . into_iter( )
364
- . flat_map( |s| s. into_iter( ) ) . collect( ) ,
365
- self . macros. clean( cx) ,
366
- ) ;
345
+ let items: Vec < Item > =
346
+ self . extern_crates . iter ( ) . map ( |x| x. clean ( cx) )
347
+ . chain ( self . imports . iter ( ) . flat_map ( |x| x. clean ( cx) . into_iter ( ) ) )
348
+ . chain ( self . structs . iter ( ) . map ( |x| x. clean ( cx) ) )
349
+ . chain ( self . enums . iter ( ) . map ( |x| x. clean ( cx) ) )
350
+ . chain ( self . fns . iter ( ) . map ( |x| x. clean ( cx) ) )
351
+ . chain ( self . foreigns . iter ( ) . flat_map ( |x| x. clean ( cx) . into_iter ( ) ) )
352
+ . chain ( self . mods . iter ( ) . map ( |x| x. clean ( cx) ) )
353
+ . chain ( self . typedefs . iter ( ) . map ( |x| x. clean ( cx) ) )
354
+ . chain ( self . statics . iter ( ) . map ( |x| x. clean ( cx) ) )
355
+ . chain ( self . constants . iter ( ) . map ( |x| x. clean ( cx) ) )
356
+ . chain ( self . traits . iter ( ) . map ( |x| x. clean ( cx) ) )
357
+ . chain ( self . impls . iter ( ) . map ( |x| x. clean ( cx) ) )
358
+ . chain ( self . macros . iter ( ) . map ( |x| x. clean ( cx) ) )
359
+ . collect ( ) ;
367
360
368
361
// determine if we should display the inner contents or
369
362
// the outer `mod` item for the source code.
@@ -389,9 +382,7 @@ impl Clean<Item> for doctree::Module {
389
382
def_id : ast_util:: local_def ( self . id ) ,
390
383
inner : ModuleItem ( Module {
391
384
is_crate : self . is_crate ,
392
- items : items. iter ( )
393
- . flat_map ( |x| x. iter ( ) . map ( |x| ( * x) . clone ( ) ) )
394
- . collect ( ) ,
385
+ items : items
395
386
} )
396
387
}
397
388
}
@@ -1989,12 +1980,21 @@ impl Clean<Item> for doctree::Impl {
1989
1980
}
1990
1981
}
1991
1982
1992
- #[ derive( Clone , RustcEncodable , RustcDecodable ) ]
1993
- pub struct ViewItem {
1994
- pub inner : ViewItemInner ,
1983
+ impl Clean < Item > for doctree:: ExternCrate {
1984
+ fn clean ( & self , cx : & DocContext ) -> Item {
1985
+ Item {
1986
+ name : None ,
1987
+ attrs : self . attrs . clean ( cx) ,
1988
+ source : self . whence . clean ( cx) ,
1989
+ def_id : ast_util:: local_def ( 0 ) ,
1990
+ visibility : self . vis . clean ( cx) ,
1991
+ stability : None ,
1992
+ inner : ExternCrateItem ( self . name . clean ( cx) , self . path . clone ( ) )
1993
+ }
1994
+ }
1995
1995
}
1996
1996
1997
- impl Clean < Vec < Item > > for ast :: ViewItem {
1997
+ impl Clean < Vec < Item > > for doctree :: Import {
1998
1998
fn clean ( & self , cx : & DocContext ) -> Vec < Item > {
1999
1999
// We consider inlining the documentation of `pub use` statements, but we
2000
2000
// forcefully don't inline if this is not public or if the
@@ -2005,81 +2005,63 @@ impl Clean<Vec<Item>> for ast::ViewItem {
2005
2005
None => false ,
2006
2006
}
2007
2007
} ) ;
2008
- let convert = |& : node: & ast:: ViewItem_ | {
2009
- Item {
2010
- name : None ,
2011
- attrs : self . attrs . clean ( cx) ,
2012
- source : self . span . clean ( cx) ,
2013
- def_id : ast_util:: local_def ( 0 ) ,
2014
- visibility : self . vis . clean ( cx) ,
2015
- stability : None ,
2016
- inner : ViewItemItem ( ViewItem { inner : node. clean ( cx) } ) ,
2008
+ let ( mut ret, inner) = match self . node {
2009
+ ast:: ViewPathGlob ( ref p) => {
2010
+ ( vec ! [ ] , GlobImport ( resolve_use_source ( cx, p. clean ( cx) , self . id ) ) )
2017
2011
}
2018
- } ;
2019
- let mut ret = Vec :: new ( ) ;
2020
- match self . node {
2021
- ast:: ViewItemUse ( ref path) if !denied => {
2022
- match path. node {
2023
- ast:: ViewPathGlob ( ..) => ret. push ( convert ( & self . node ) ) ,
2024
- ast:: ViewPathList ( ref a, ref list, ref b) => {
2025
- // Attempt to inline all reexported items, but be sure
2026
- // to keep any non-inlineable reexports so they can be
2027
- // listed in the documentation.
2028
- let remaining = list. iter ( ) . filter ( |path| {
2029
- match inline:: try_inline ( cx, path. node . id ( ) , None ) {
2030
- Some ( items) => {
2031
- ret. extend ( items. into_iter ( ) ) ; false
2032
- }
2033
- None => true ,
2012
+ ast:: ViewPathList ( ref p, ref list) => {
2013
+ // Attempt to inline all reexported items, but be sure
2014
+ // to keep any non-inlineable reexports so they can be
2015
+ // listed in the documentation.
2016
+ let mut ret = vec ! [ ] ;
2017
+ let remaining = if !denied {
2018
+ let mut remaining = vec ! [ ] ;
2019
+ for path in list. iter ( ) {
2020
+ match inline:: try_inline ( cx, path. node . id ( ) , None ) {
2021
+ Some ( items) => {
2022
+ ret. extend ( items. into_iter ( ) ) ;
2023
+ }
2024
+ None => {
2025
+ remaining. push ( path. clean ( cx) ) ;
2034
2026
}
2035
- } ) . map ( |a| a. clone ( ) ) . collect :: < Vec < ast:: PathListItem > > ( ) ;
2036
- if remaining. len ( ) > 0 {
2037
- let path = ast:: ViewPathList ( a. clone ( ) ,
2038
- remaining,
2039
- b. clone ( ) ) ;
2040
- let path = syntax:: codemap:: dummy_spanned ( path) ;
2041
- ret. push ( convert ( & ast:: ViewItemUse ( P ( path) ) ) ) ;
2042
- }
2043
- }
2044
- ast:: ViewPathSimple ( ident, _, id) => {
2045
- match inline:: try_inline ( cx, id, Some ( ident) ) {
2046
- Some ( items) => ret. extend ( items. into_iter ( ) ) ,
2047
- None => ret. push ( convert ( & self . node ) ) ,
2048
2027
}
2049
2028
}
2050
- }
2051
- }
2052
- ref n => ret. push ( convert ( n) ) ,
2053
- }
2054
- return ret;
2055
- }
2056
- }
2057
-
2058
- #[ derive( Clone , RustcEncodable , RustcDecodable ) ]
2059
- pub enum ViewItemInner {
2060
- ExternCrate ( String , Option < String > , ast:: NodeId ) ,
2061
- Import ( ViewPath )
2062
- }
2063
-
2064
- impl Clean < ViewItemInner > for ast:: ViewItem_ {
2065
- fn clean ( & self , cx : & DocContext ) -> ViewItemInner {
2066
- match self {
2067
- & ast:: ViewItemExternCrate ( ref i, ref p, ref id) => {
2068
- let string = match * p {
2069
- None => None ,
2070
- Some ( ( ref x, _) ) => Some ( x. get ( ) . to_string ( ) ) ,
2029
+ remaining
2030
+ } else {
2031
+ list. clean ( cx)
2071
2032
} ;
2072
- ExternCrate ( i. clean ( cx) , string, * id)
2033
+ if remaining. is_empty ( ) {
2034
+ return ret;
2035
+ }
2036
+ ( ret, ImportList ( resolve_use_source ( cx, p. clean ( cx) , self . id ) ,
2037
+ remaining) )
2073
2038
}
2074
- & ast:: ViewItemUse ( ref vp) => {
2075
- Import ( vp. clean ( cx) )
2039
+ ast:: ViewPathSimple ( i, ref p) => {
2040
+ if !denied {
2041
+ match inline:: try_inline ( cx, self . id , Some ( i) ) {
2042
+ Some ( items) => return items,
2043
+ None => { }
2044
+ }
2045
+ }
2046
+ ( vec ! [ ] , SimpleImport ( i. clean ( cx) ,
2047
+ resolve_use_source ( cx, p. clean ( cx) , self . id ) ) )
2076
2048
}
2077
- }
2049
+ } ;
2050
+ ret. push ( Item {
2051
+ name : None ,
2052
+ attrs : self . attrs . clean ( cx) ,
2053
+ source : self . whence . clean ( cx) ,
2054
+ def_id : ast_util:: local_def ( 0 ) ,
2055
+ visibility : self . vis . clean ( cx) ,
2056
+ stability : None ,
2057
+ inner : ImportItem ( inner)
2058
+ } ) ;
2059
+ ret
2078
2060
}
2079
2061
}
2080
2062
2081
2063
#[ derive( Clone , RustcEncodable , RustcDecodable ) ]
2082
- pub enum ViewPath {
2064
+ pub enum Import {
2083
2065
// use source as str;
2084
2066
SimpleImport ( String , ImportSource ) ,
2085
2067
// use source::*;
@@ -2094,21 +2076,6 @@ pub struct ImportSource {
2094
2076
pub did : Option < ast:: DefId > ,
2095
2077
}
2096
2078
2097
- impl Clean < ViewPath > for ast:: ViewPath {
2098
- fn clean ( & self , cx : & DocContext ) -> ViewPath {
2099
- match self . node {
2100
- ast:: ViewPathSimple ( ref i, ref p, id) =>
2101
- SimpleImport ( i. clean ( cx) , resolve_use_source ( cx, p. clean ( cx) , id) ) ,
2102
- ast:: ViewPathGlob ( ref p, id) =>
2103
- GlobImport ( resolve_use_source ( cx, p. clean ( cx) , id) ) ,
2104
- ast:: ViewPathList ( ref p, ref pl, id) => {
2105
- ImportList ( resolve_use_source ( cx, p. clean ( cx) , id) ,
2106
- pl. clean ( cx) )
2107
- }
2108
- }
2109
- }
2110
- }
2111
-
2112
2079
#[ derive( Clone , RustcEncodable , RustcDecodable ) ]
2113
2080
pub struct ViewListIdent {
2114
2081
pub name : String ,
0 commit comments