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