@@ -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 ( ) => {
@@ -1491,45 +1484,50 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
1491
1484
!cx. ignore_private_item ( & items[ * i] )
1492
1485
} ) . collect :: < Vec < uint > > ( ) ;
1493
1486
1487
+ // the order of item types in the listing
1488
+ fn reorder ( ty : ItemType ) -> u8 {
1489
+ match ty {
1490
+ ItemType :: ViewItem => 0 ,
1491
+ ItemType :: Primitive => 1 ,
1492
+ ItemType :: Module => 2 ,
1493
+ ItemType :: Macro => 3 ,
1494
+ ItemType :: Struct => 4 ,
1495
+ ItemType :: Enum => 5 ,
1496
+ ItemType :: Constant => 6 ,
1497
+ ItemType :: Static => 7 ,
1498
+ ItemType :: ForeignFunction => 8 ,
1499
+ ItemType :: ForeignStatic => 9 ,
1500
+ ItemType :: Trait => 10 ,
1501
+ ItemType :: Function => 11 ,
1502
+ ItemType :: Typedef => 12 ,
1503
+ _ => 13 + ty as u8 ,
1504
+ }
1505
+ }
1506
+
1494
1507
fn cmp ( i1 : & clean:: Item , i2 : & clean:: Item , idx1 : uint , idx2 : uint ) -> Ordering {
1495
- if shortty ( i1) == shortty ( i2) {
1508
+ let ty1 = shortty ( i1) ;
1509
+ let ty2 = shortty ( i2) ;
1510
+ if ty1 == ty2 {
1496
1511
return i1. name . cmp ( & i2. name ) ;
1497
1512
}
1498
- match ( & i1. inner , & i2. inner ) {
1499
- ( & clean:: ViewItemItem ( ref a) , & clean:: ViewItemItem ( ref b) ) => {
1500
- match ( & a. inner , & b. inner ) {
1501
- ( & clean:: ExternCrate ( ..) , _) => Less ,
1502
- ( _, & clean:: ExternCrate ( ..) ) => Greater ,
1503
- _ => idx1. cmp ( & idx2) ,
1513
+
1514
+ let tycmp = reorder ( ty1) . cmp ( & reorder ( ty2) ) ;
1515
+ if let Equal = tycmp {
1516
+ // for reexports, `extern crate` takes precedence.
1517
+ match ( & i1. inner , & i2. inner ) {
1518
+ ( & clean:: ViewItemItem ( ref a) , & clean:: ViewItemItem ( ref b) ) => {
1519
+ match ( & a. inner , & b. inner ) {
1520
+ ( & clean:: ExternCrate ( ..) , _) => return Less ,
1521
+ ( _, & clean:: ExternCrate ( ..) ) => return Greater ,
1522
+ _ => { }
1523
+ }
1504
1524
}
1525
+ ( _, _) => { }
1505
1526
}
1506
- ( & clean:: ViewItemItem ( ..) , _) => Less ,
1507
- ( _, & clean:: ViewItemItem ( ..) ) => Greater ,
1508
- ( & clean:: PrimitiveItem ( ..) , _) => Less ,
1509
- ( _, & clean:: PrimitiveItem ( ..) ) => Greater ,
1510
- ( & clean:: ModuleItem ( ..) , _) => Less ,
1511
- ( _, & clean:: ModuleItem ( ..) ) => Greater ,
1512
- ( & clean:: MacroItem ( ..) , _) => Less ,
1513
- ( _, & clean:: MacroItem ( ..) ) => Greater ,
1514
- ( & clean:: StructItem ( ..) , _) => Less ,
1515
- ( _, & clean:: StructItem ( ..) ) => Greater ,
1516
- ( & clean:: EnumItem ( ..) , _) => Less ,
1517
- ( _, & clean:: EnumItem ( ..) ) => Greater ,
1518
- ( & clean:: ConstantItem ( ..) , _) => Less ,
1519
- ( _, & clean:: ConstantItem ( ..) ) => Greater ,
1520
- ( & clean:: StaticItem ( ..) , _) => Less ,
1521
- ( _, & clean:: StaticItem ( ..) ) => Greater ,
1522
- ( & clean:: ForeignFunctionItem ( ..) , _) => Less ,
1523
- ( _, & clean:: ForeignFunctionItem ( ..) ) => Greater ,
1524
- ( & clean:: ForeignStaticItem ( ..) , _) => Less ,
1525
- ( _, & clean:: ForeignStaticItem ( ..) ) => Greater ,
1526
- ( & clean:: TraitItem ( ..) , _) => Less ,
1527
- ( _, & clean:: TraitItem ( ..) ) => Greater ,
1528
- ( & clean:: FunctionItem ( ..) , _) => Less ,
1529
- ( _, & clean:: FunctionItem ( ..) ) => Greater ,
1530
- ( & clean:: TypedefItem ( ..) , _) => Less ,
1531
- ( _, & clean:: TypedefItem ( ..) ) => Greater ,
1532
- _ => idx1. cmp ( & idx2) ,
1527
+
1528
+ idx1. cmp ( & idx2)
1529
+ } else {
1530
+ tycmp
1533
1531
}
1534
1532
}
1535
1533
@@ -1546,26 +1544,26 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
1546
1544
try!( write ! ( w, "</table>" ) ) ;
1547
1545
}
1548
1546
curty = myty;
1549
- let ( short, name) = match myitem . inner {
1550
- clean :: ModuleItem ( .. ) => ( "modules" , "Modules" ) ,
1551
- clean :: StructItem ( .. ) => ( "structs" , "Structs" ) ,
1552
- clean :: EnumItem ( .. ) => ( "enums" , "Enums" ) ,
1553
- clean :: FunctionItem ( .. ) => ( "functions" , "Functions" ) ,
1554
- clean :: TypedefItem ( .. ) => ( "types" , "Type Definitions" ) ,
1555
- clean :: StaticItem ( .. ) => ( "statics" , "Statics" ) ,
1556
- clean :: ConstantItem ( .. ) => ( "constants" , "Constants" ) ,
1557
- clean :: TraitItem ( .. ) => ( "traits" , "Traits" ) ,
1558
- clean :: ImplItem ( .. ) => ( "impls" , "Implementations" ) ,
1559
- clean :: ViewItemItem ( .. ) => ( "reexports" , "Reexports" ) ,
1560
- clean :: TyMethodItem ( .. ) => ( "tymethods" , "Type Methods" ) ,
1561
- clean :: MethodItem ( .. ) => ( "methods" , "Methods" ) ,
1562
- clean :: StructFieldItem ( .. ) => ( "fields" , "Struct Fields" ) ,
1563
- clean :: VariantItem ( .. ) => ( "variants" , "Variants" ) ,
1564
- clean :: ForeignFunctionItem ( .. ) => ( "ffi-fns" , "Foreign Functions" ) ,
1565
- clean :: ForeignStaticItem ( .. ) => ( "ffi-statics" , "Foreign Statics" ) ,
1566
- clean :: MacroItem ( .. ) => ( "macros" , "Macros" ) ,
1567
- clean :: PrimitiveItem ( .. ) => ( "primitives" , "Primitive Types" ) ,
1568
- clean :: AssociatedTypeItem ( .. ) => ( "associated-types" , "Associated Types" ) ,
1547
+ let ( short, name) = match myty . unwrap ( ) {
1548
+ ItemType :: Module => ( "modules" , "Modules" ) ,
1549
+ ItemType :: Struct => ( "structs" , "Structs" ) ,
1550
+ ItemType :: Enum => ( "enums" , "Enums" ) ,
1551
+ ItemType :: Function => ( "functions" , "Functions" ) ,
1552
+ ItemType :: Typedef => ( "types" , "Type Definitions" ) ,
1553
+ ItemType :: Static => ( "statics" , "Statics" ) ,
1554
+ ItemType :: Constant => ( "constants" , "Constants" ) ,
1555
+ ItemType :: Trait => ( "traits" , "Traits" ) ,
1556
+ ItemType :: Impl => ( "impls" , "Implementations" ) ,
1557
+ ItemType :: ViewItem => ( "reexports" , "Reexports" ) ,
1558
+ ItemType :: TyMethod => ( "tymethods" , "Type Methods" ) ,
1559
+ ItemType :: Method => ( "methods" , "Methods" ) ,
1560
+ ItemType :: StructField => ( "fields" , "Struct Fields" ) ,
1561
+ ItemType :: Variant => ( "variants" , "Variants" ) ,
1562
+ ItemType :: ForeignFunction => ( "ffi-fns" , "Foreign Functions" ) ,
1563
+ ItemType :: ForeignStatic => ( "ffi-statics" , "Foreign Statics" ) ,
1564
+ ItemType :: Macro => ( "macros" , "Macros" ) ,
1565
+ ItemType :: Primitive => ( "primitives" , "Primitive Types" ) ,
1566
+ ItemType :: AssociatedType => ( "associated-types" , "Associated Types" ) ,
1569
1567
} ;
1570
1568
try!( write ! ( w,
1571
1569
"<h2 id='{id}' class='section-header'>\
0 commit comments