@@ -61,8 +61,7 @@ use fold::DocFolder;
61
61
use html:: format:: { VisSpace , Method , FnStyleSpace , MutableSpace , Stability } ;
62
62
use html:: format:: { ConciseStability , TyParamBounds , WhereClause } ;
63
63
use html:: highlight;
64
- use html:: item_type:: { ItemType , shortty} ;
65
- use html:: item_type;
64
+ use html:: item_type:: ItemType ;
66
65
use html:: layout;
67
66
use html:: markdown:: Markdown ;
68
67
use html:: markdown;
@@ -314,19 +313,8 @@ pub fn run(mut krate: clean::Crate,
314
313
let paths: HashMap < ast:: DefId , ( Vec < String > , ItemType ) > =
315
314
analysis. as_ref ( ) . map ( |a| {
316
315
let paths = a. external_paths . borrow_mut ( ) . take ( ) . unwrap ( ) ;
317
- paths. into_iter ( ) . map ( |( k, ( v, t) ) | {
318
- ( k, ( v, match t {
319
- clean:: TypeStruct => item_type:: Struct ,
320
- clean:: TypeEnum => item_type:: Enum ,
321
- clean:: TypeFunction => item_type:: Function ,
322
- clean:: TypeTrait => item_type:: Trait ,
323
- clean:: TypeModule => item_type:: Module ,
324
- clean:: TypeStatic => item_type:: Static ,
325
- clean:: TypeVariant => item_type:: Variant ,
326
- clean:: TypeTypedef => item_type:: Typedef ,
327
- } ) )
328
- } ) . collect ( )
329
- } ) . unwrap_or ( HashMap :: new ( ) ) ;
316
+ paths. into_iter ( ) . map ( |( k, ( v, t) ) | ( k, ( v, ItemType :: from_type_kind ( t) ) ) ) . collect ( )
317
+ } ) . unwrap_or ( HashMap :: new ( ) ) ;
330
318
let mut cache = Cache {
331
319
impls : HashMap :: new ( ) ,
332
320
external_paths : paths. iter ( ) . map ( |( & k, v) | ( k, v. ref0 ( ) . clone ( ) ) )
@@ -359,7 +347,7 @@ pub fn run(mut krate: clean::Crate,
359
347
for & ( n, ref e) in krate. externs . iter ( ) {
360
348
cache. extern_locations . insert ( n, extern_location ( e, & cx. dst ) ) ;
361
349
let did = ast:: DefId { krate : n, node : ast:: CRATE_NODE_ID } ;
362
- cache. paths . insert ( did, ( vec ! [ e. name. to_string( ) ] , item_type :: Module ) ) ;
350
+ cache. paths . insert ( did, ( vec ! [ e. name. to_string( ) ] , ItemType :: Module ) ) ;
363
351
}
364
352
365
353
// Cache where all known primitives have their documentation located.
@@ -642,6 +630,11 @@ fn mkdir(path: &Path) -> io::IoResult<()> {
642
630
}
643
631
}
644
632
633
+ /// Returns a documentation-level item type from the item.
634
+ fn shortty ( item : & clean:: Item ) -> ItemType {
635
+ ItemType :: from_item ( item)
636
+ }
637
+
645
638
/// Takes a path to a source file and cleans the path to it. This canonicalizes
646
639
/// things like ".." to components which preserve the "top down" hierarchy of a
647
640
/// static HTML tree.
@@ -855,13 +848,13 @@ impl DocFolder for Cache {
855
848
let last = self . parent_stack . last ( ) . unwrap ( ) ;
856
849
let did = * last;
857
850
let path = match self . paths . get ( & did) {
858
- Some ( & ( _, item_type :: Trait ) ) =>
851
+ Some ( & ( _, ItemType :: Trait ) ) =>
859
852
Some ( self . stack [ ..self . stack . len ( ) - 1 ] ) ,
860
853
// The current stack not necessarily has correlation for
861
854
// where the type was defined. On the other hand,
862
855
// `paths` always has the right information if present.
863
- Some ( & ( ref fqp, item_type :: Struct ) ) |
864
- Some ( & ( ref fqp, item_type :: Enum ) ) =>
856
+ Some ( & ( ref fqp, ItemType :: Struct ) ) |
857
+ Some ( & ( ref fqp, ItemType :: Enum ) ) =>
865
858
Some ( fqp[ ..fqp. len ( ) - 1 ] ) ,
866
859
Some ( ..) => Some ( self . stack . as_slice ( ) ) ,
867
860
None => None
@@ -929,7 +922,7 @@ impl DocFolder for Cache {
929
922
clean:: VariantItem ( ..) if !self . privmod => {
930
923
let mut stack = self . stack . clone ( ) ;
931
924
stack. pop ( ) ;
932
- self . paths . insert ( item. def_id , ( stack, item_type :: Enum ) ) ;
925
+ self . paths . insert ( item. def_id , ( stack, ItemType :: Enum ) ) ;
933
926
}
934
927
935
928
clean:: PrimitiveItem ( ..) if item. visibility . is_some ( ) => {
@@ -1251,6 +1244,10 @@ impl Context {
1251
1244
for item in m. items . iter ( ) {
1252
1245
if self . ignore_private_item ( item) { continue }
1253
1246
1247
+ // avoid putting foreign items to the sidebar.
1248
+ if let & clean:: ForeignFunctionItem ( ..) = & item. inner { continue }
1249
+ if let & clean:: ForeignStaticItem ( ..) = & item. inner { continue }
1250
+
1254
1251
let short = shortty ( item) . to_static_str ( ) ;
1255
1252
let myname = match item. name {
1256
1253
None => continue ,
@@ -1435,7 +1432,8 @@ impl<'a> fmt::Show for Item<'a> {
1435
1432
clean:: TypedefItem ( ref t) => item_typedef ( fmt, self . item , t) ,
1436
1433
clean:: MacroItem ( ref m) => item_macro ( fmt, self . item , m) ,
1437
1434
clean:: PrimitiveItem ( ref p) => item_primitive ( fmt, self . item , p) ,
1438
- clean:: StaticItem ( ref i) => item_static ( fmt, self . item , i) ,
1435
+ clean:: StaticItem ( ref i) | clean:: ForeignStaticItem ( ref i) =>
1436
+ item_static ( fmt, self . item , i) ,
1439
1437
clean:: ConstantItem ( ref c) => item_constant ( fmt, self . item , c) ,
1440
1438
_ => Ok ( ( ) )
1441
1439
}
@@ -1490,45 +1488,48 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
1490
1488
!cx. ignore_private_item ( & items[ * i] )
1491
1489
} ) . collect :: < Vec < uint > > ( ) ;
1492
1490
1491
+ // the order of item types in the listing
1492
+ fn reorder ( ty : ItemType ) -> u8 {
1493
+ match ty {
1494
+ ItemType :: ViewItem => 0 ,
1495
+ ItemType :: Primitive => 1 ,
1496
+ ItemType :: Module => 2 ,
1497
+ ItemType :: Macro => 3 ,
1498
+ ItemType :: Struct => 4 ,
1499
+ ItemType :: Enum => 5 ,
1500
+ ItemType :: Constant => 6 ,
1501
+ ItemType :: Static => 7 ,
1502
+ ItemType :: Trait => 8 ,
1503
+ ItemType :: Function => 9 ,
1504
+ ItemType :: Typedef => 10 ,
1505
+ _ => 11 + ty as u8 ,
1506
+ }
1507
+ }
1508
+
1493
1509
fn cmp ( i1 : & clean:: Item , i2 : & clean:: Item , idx1 : uint , idx2 : uint ) -> Ordering {
1494
- if shortty ( i1) == shortty ( i2) {
1510
+ let ty1 = shortty ( i1) ;
1511
+ let ty2 = shortty ( i2) ;
1512
+ if ty1 == ty2 {
1495
1513
return i1. name . cmp ( & i2. name ) ;
1496
1514
}
1497
- match ( & i1. inner , & i2. inner ) {
1498
- ( & clean:: ViewItemItem ( ref a) , & clean:: ViewItemItem ( ref b) ) => {
1499
- match ( & a. inner , & b. inner ) {
1500
- ( & clean:: ExternCrate ( ..) , _) => Less ,
1501
- ( _, & clean:: ExternCrate ( ..) ) => Greater ,
1502
- _ => idx1. cmp ( & idx2) ,
1515
+
1516
+ let tycmp = reorder ( ty1) . cmp ( & reorder ( ty2) ) ;
1517
+ if let Equal = tycmp {
1518
+ // for reexports, `extern crate` takes precedence.
1519
+ match ( & i1. inner , & i2. inner ) {
1520
+ ( & clean:: ViewItemItem ( ref a) , & clean:: ViewItemItem ( ref b) ) => {
1521
+ match ( & a. inner , & b. inner ) {
1522
+ ( & clean:: ExternCrate ( ..) , _) => return Less ,
1523
+ ( _, & clean:: ExternCrate ( ..) ) => return Greater ,
1524
+ _ => { }
1525
+ }
1503
1526
}
1527
+ ( _, _) => { }
1504
1528
}
1505
- ( & clean:: ViewItemItem ( ..) , _) => Less ,
1506
- ( _, & clean:: ViewItemItem ( ..) ) => Greater ,
1507
- ( & clean:: PrimitiveItem ( ..) , _) => Less ,
1508
- ( _, & clean:: PrimitiveItem ( ..) ) => Greater ,
1509
- ( & clean:: ModuleItem ( ..) , _) => Less ,
1510
- ( _, & clean:: ModuleItem ( ..) ) => Greater ,
1511
- ( & clean:: MacroItem ( ..) , _) => Less ,
1512
- ( _, & clean:: MacroItem ( ..) ) => Greater ,
1513
- ( & clean:: StructItem ( ..) , _) => Less ,
1514
- ( _, & clean:: StructItem ( ..) ) => Greater ,
1515
- ( & clean:: EnumItem ( ..) , _) => Less ,
1516
- ( _, & clean:: EnumItem ( ..) ) => Greater ,
1517
- ( & clean:: ConstantItem ( ..) , _) => Less ,
1518
- ( _, & clean:: ConstantItem ( ..) ) => Greater ,
1519
- ( & clean:: StaticItem ( ..) , _) => Less ,
1520
- ( _, & clean:: StaticItem ( ..) ) => Greater ,
1521
- ( & clean:: ForeignFunctionItem ( ..) , _) => Less ,
1522
- ( _, & clean:: ForeignFunctionItem ( ..) ) => Greater ,
1523
- ( & clean:: ForeignStaticItem ( ..) , _) => Less ,
1524
- ( _, & clean:: ForeignStaticItem ( ..) ) => Greater ,
1525
- ( & clean:: TraitItem ( ..) , _) => Less ,
1526
- ( _, & clean:: TraitItem ( ..) ) => Greater ,
1527
- ( & clean:: FunctionItem ( ..) , _) => Less ,
1528
- ( _, & clean:: FunctionItem ( ..) ) => Greater ,
1529
- ( & clean:: TypedefItem ( ..) , _) => Less ,
1530
- ( _, & clean:: TypedefItem ( ..) ) => Greater ,
1531
- _ => idx1. cmp ( & idx2) ,
1529
+
1530
+ idx1. cmp ( & idx2)
1531
+ } else {
1532
+ tycmp
1532
1533
}
1533
1534
}
1534
1535
@@ -1545,26 +1546,24 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
1545
1546
try!( write ! ( w, "</table>" ) ) ;
1546
1547
}
1547
1548
curty = myty;
1548
- let ( short, name) = match myitem. inner {
1549
- clean:: ModuleItem ( ..) => ( "modules" , "Modules" ) ,
1550
- clean:: StructItem ( ..) => ( "structs" , "Structs" ) ,
1551
- clean:: EnumItem ( ..) => ( "enums" , "Enums" ) ,
1552
- clean:: FunctionItem ( ..) => ( "functions" , "Functions" ) ,
1553
- clean:: TypedefItem ( ..) => ( "types" , "Type Definitions" ) ,
1554
- clean:: StaticItem ( ..) => ( "statics" , "Statics" ) ,
1555
- clean:: ConstantItem ( ..) => ( "constants" , "Constants" ) ,
1556
- clean:: TraitItem ( ..) => ( "traits" , "Traits" ) ,
1557
- clean:: ImplItem ( ..) => ( "impls" , "Implementations" ) ,
1558
- clean:: ViewItemItem ( ..) => ( "reexports" , "Reexports" ) ,
1559
- clean:: TyMethodItem ( ..) => ( "tymethods" , "Type Methods" ) ,
1560
- clean:: MethodItem ( ..) => ( "methods" , "Methods" ) ,
1561
- clean:: StructFieldItem ( ..) => ( "fields" , "Struct Fields" ) ,
1562
- clean:: VariantItem ( ..) => ( "variants" , "Variants" ) ,
1563
- clean:: ForeignFunctionItem ( ..) => ( "ffi-fns" , "Foreign Functions" ) ,
1564
- clean:: ForeignStaticItem ( ..) => ( "ffi-statics" , "Foreign Statics" ) ,
1565
- clean:: MacroItem ( ..) => ( "macros" , "Macros" ) ,
1566
- clean:: PrimitiveItem ( ..) => ( "primitives" , "Primitive Types" ) ,
1567
- clean:: AssociatedTypeItem ( ..) => ( "associated-types" , "Associated Types" ) ,
1549
+ let ( short, name) = match myty. unwrap ( ) {
1550
+ ItemType :: Module => ( "modules" , "Modules" ) ,
1551
+ ItemType :: Struct => ( "structs" , "Structs" ) ,
1552
+ ItemType :: Enum => ( "enums" , "Enums" ) ,
1553
+ ItemType :: Function => ( "functions" , "Functions" ) ,
1554
+ ItemType :: Typedef => ( "types" , "Type Definitions" ) ,
1555
+ ItemType :: Static => ( "statics" , "Statics" ) ,
1556
+ ItemType :: Constant => ( "constants" , "Constants" ) ,
1557
+ ItemType :: Trait => ( "traits" , "Traits" ) ,
1558
+ ItemType :: Impl => ( "impls" , "Implementations" ) ,
1559
+ ItemType :: ViewItem => ( "reexports" , "Reexports" ) ,
1560
+ ItemType :: TyMethod => ( "tymethods" , "Type Methods" ) ,
1561
+ ItemType :: Method => ( "methods" , "Methods" ) ,
1562
+ ItemType :: StructField => ( "fields" , "Struct Fields" ) ,
1563
+ ItemType :: Variant => ( "variants" , "Variants" ) ,
1564
+ ItemType :: Macro => ( "macros" , "Macros" ) ,
1565
+ ItemType :: Primitive => ( "primitives" , "Primitive Types" ) ,
1566
+ ItemType :: AssociatedType => ( "associated-types" , "Associated Types" ) ,
1568
1567
} ;
1569
1568
try!( write ! ( w,
1570
1569
"<h2 id='{id}' class='section-header'>\
0 commit comments