@@ -61,8 +61,7 @@ use fold::DocFolder;
6161use html:: format:: { VisSpace , Method , FnStyleSpace , MutableSpace , Stability } ;
6262use html:: format:: { ConciseStability , TyParamBounds , WhereClause } ;
6363use html:: highlight;
64- use html:: item_type:: { ItemType , shortty} ;
65- use html:: item_type;
64+ use html:: item_type:: ItemType ;
6665use html:: layout;
6766use html:: markdown:: Markdown ;
6867use html:: markdown;
@@ -314,19 +313,8 @@ pub fn run(mut krate: clean::Crate,
314313 let paths: HashMap < ast:: DefId , ( Vec < String > , ItemType ) > =
315314 analysis. as_ref ( ) . map ( |a| {
316315 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 ( ) ) ;
330318 let mut cache = Cache {
331319 impls : HashMap :: new ( ) ,
332320 external_paths : paths. iter ( ) . map ( |( & k, v) | ( k, v. ref0 ( ) . clone ( ) ) )
@@ -359,7 +347,7 @@ pub fn run(mut krate: clean::Crate,
359347 for & ( n, ref e) in krate. externs . iter ( ) {
360348 cache. extern_locations . insert ( n, extern_location ( e, & cx. dst ) ) ;
361349 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 ) ) ;
363351 }
364352
365353 // Cache where all known primitives have their documentation located.
@@ -642,6 +630,11 @@ fn mkdir(path: &Path) -> io::IoResult<()> {
642630 }
643631}
644632
633+ /// Returns a documentation-level item type from the item.
634+ fn shortty ( item : & clean:: Item ) -> ItemType {
635+ ItemType :: from_item ( item)
636+ }
637+
645638/// Takes a path to a source file and cleans the path to it. This canonicalizes
646639/// things like ".." to components which preserve the "top down" hierarchy of a
647640/// static HTML tree.
@@ -855,13 +848,13 @@ impl DocFolder for Cache {
855848 let last = self . parent_stack . last ( ) . unwrap ( ) ;
856849 let did = * last;
857850 let path = match self . paths . get ( & did) {
858- Some ( & ( _, item_type :: Trait ) ) =>
851+ Some ( & ( _, ItemType :: Trait ) ) =>
859852 Some ( self . stack [ ..self . stack . len ( ) - 1 ] ) ,
860853 // The current stack not necessarily has correlation for
861854 // where the type was defined. On the other hand,
862855 // `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 ) ) =>
865858 Some ( fqp[ ..fqp. len ( ) - 1 ] ) ,
866859 Some ( ..) => Some ( self . stack . as_slice ( ) ) ,
867860 None => None
@@ -929,7 +922,7 @@ impl DocFolder for Cache {
929922 clean:: VariantItem ( ..) if !self . privmod => {
930923 let mut stack = self . stack . clone ( ) ;
931924 stack. pop ( ) ;
932- self . paths . insert ( item. def_id , ( stack, item_type :: Enum ) ) ;
925+ self . paths . insert ( item. def_id , ( stack, ItemType :: Enum ) ) ;
933926 }
934927
935928 clean:: PrimitiveItem ( ..) if item. visibility . is_some ( ) => {
@@ -1491,45 +1484,50 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
14911484 !cx. ignore_private_item ( & items[ * i] )
14921485 } ) . collect :: < Vec < uint > > ( ) ;
14931486
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+
14941507 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 {
14961511 return i1. name . cmp ( & i2. name ) ;
14971512 }
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+ }
15041524 }
1525+ ( _, _) => { }
15051526 }
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
15331531 }
15341532 }
15351533
@@ -1546,26 +1544,26 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
15461544 try!( write ! ( w, "</table>" ) ) ;
15471545 }
15481546 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" ) ,
15691567 } ;
15701568 try!( write ! ( w,
15711569 "<h2 id='{id}' class='section-header'>\
0 commit comments