@@ -1703,7 +1703,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
1703
1703
"<div class=\" block version\" >\
1704
1704
<p>Version {}</p>\
1705
1705
</div>",
1706
- Escape ( version)
1706
+ Escape ( version) ,
1707
1707
) ;
1708
1708
}
1709
1709
}
@@ -1713,9 +1713,10 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
1713
1713
write ! (
1714
1714
buffer,
1715
1715
"<a id=\" all-types\" href=\" all.html\" ><p>See all {}'s items</p></a>" ,
1716
- it. name. as_ref( ) . expect( "crates always have a name" )
1716
+ it. name. as_ref( ) . expect( "crates always have a name" ) ,
1717
1717
) ;
1718
1718
}
1719
+
1719
1720
match * it. kind {
1720
1721
clean:: StructItem ( ref s) => sidebar_struct ( cx, buffer, it, s) ,
1721
1722
clean:: TraitItem ( ref t) => sidebar_trait ( cx, buffer, it, t) ,
@@ -1725,7 +1726,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
1725
1726
clean:: TypedefItem ( _, _) => sidebar_typedef ( cx, buffer, it) ,
1726
1727
clean:: ModuleItem ( ref m) => sidebar_module ( buffer, & m. items ) ,
1727
1728
clean:: ForeignTypeItem => sidebar_foreign_type ( cx, buffer, it) ,
1728
- _ => ( ) ,
1729
+ _ => { }
1729
1730
}
1730
1731
1731
1732
// The sidebar is designed to display sibling functions, modules and
@@ -1736,22 +1737,24 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
1736
1737
// as much HTML as possible in order to allow non-JS-enabled browsers
1737
1738
// to navigate the documentation (though slightly inefficiently).
1738
1739
1739
- buffer. write_str ( "<p class=\" location\" >" ) ;
1740
- for ( i, name) in cx. current . iter ( ) . take ( parentlen) . enumerate ( ) {
1741
- if i > 0 {
1742
- buffer. write_str ( "::<wbr>" ) ;
1740
+ if !it. is_mod ( ) {
1741
+ buffer. write_str ( "<p class=\" location\" >" ) ;
1742
+ for ( i, name) in cx. current . iter ( ) . take ( parentlen) . enumerate ( ) {
1743
+ if i > 0 {
1744
+ buffer. write_str ( "::<wbr>" ) ;
1745
+ }
1746
+ write ! (
1747
+ buffer,
1748
+ "<a href=\" {}index.html\" >{}</a>" ,
1749
+ & cx. root_path( ) [ ..( cx. current. len( ) - i - 1 ) * 3 ] ,
1750
+ * name
1751
+ ) ;
1743
1752
}
1744
- write ! (
1745
- buffer,
1746
- "<a href=\" {}index.html\" >{}</a>" ,
1747
- & cx. root_path( ) [ ..( cx. current. len( ) - i - 1 ) * 3 ] ,
1748
- * name
1749
- ) ;
1753
+ buffer. write_str ( "</p>" ) ;
1750
1754
}
1751
- buffer. write_str ( "</p>" ) ;
1752
1755
1753
1756
// Sidebar refers to the enclosing module, not this module.
1754
- let relpath = if it. is_mod ( ) { ". ./" } else { "" } ;
1757
+ let relpath = if it. is_mod ( ) && parentlen != 0 { "./" } else { "" } ;
1755
1758
write ! (
1756
1759
buffer,
1757
1760
"<div id=\" sidebar-vars\" data-name=\" {name}\" data-ty=\" {ty}\" data-relpath=\" {path}\" >\
@@ -1760,17 +1763,7 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) {
1760
1763
ty = it. type_( ) ,
1761
1764
path = relpath
1762
1765
) ;
1763
-
1764
- if parentlen == 0 {
1765
- write ! (
1766
- buffer,
1767
- "<script defer src=\" {}sidebar-items{}.js\" ></script>" ,
1768
- relpath, cx. shared. resource_suffix
1769
- ) ;
1770
- } else {
1771
- write ! ( buffer, "<script defer src=\" {}sidebar-items.js\" ></script>" , relpath) ;
1772
- }
1773
-
1766
+ write ! ( buffer, "<script defer src=\" {}sidebar-items.js\" ></script>" , relpath) ;
1774
1767
// Closes sidebar-elems div.
1775
1768
buffer. write_str ( "</div>" ) ;
1776
1769
}
@@ -2278,8 +2271,8 @@ fn sidebar_enum(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, e: &clean:
2278
2271
}
2279
2272
}
2280
2273
2281
- fn item_ty_to_strs ( ty : & ItemType ) -> ( & ' static str , & ' static str ) {
2282
- match * ty {
2274
+ fn item_ty_to_strs ( ty : ItemType ) -> ( & ' static str , & ' static str ) {
2275
+ match ty {
2283
2276
ItemType :: ExternCrate | ItemType :: Import => ( "reexports" , "Re-exports" ) ,
2284
2277
ItemType :: Module => ( "modules" , "Modules" ) ,
2285
2278
ItemType :: Struct => ( "structs" , "Structs" ) ,
@@ -2311,10 +2304,14 @@ fn item_ty_to_strs(ty: &ItemType) -> (&'static str, &'static str) {
2311
2304
fn sidebar_module ( buf : & mut Buffer , items : & [ clean:: Item ] ) {
2312
2305
let mut sidebar = String :: new ( ) ;
2313
2306
2307
+ // Re-exports are handled a bit differently because they can be extern crates or imports.
2314
2308
if items. iter ( ) . any ( |it| {
2315
- it. type_ ( ) == ItemType :: ExternCrate || ( it. type_ ( ) == ItemType :: Import && !it. is_stripped ( ) )
2309
+ it. name . is_some ( )
2310
+ && ( it. type_ ( ) == ItemType :: ExternCrate
2311
+ || ( it. type_ ( ) == ItemType :: Import && !it. is_stripped ( ) ) )
2316
2312
} ) {
2317
- sidebar. push_str ( "<li><a href=\" #reexports\" >Re-exports</a></li>" ) ;
2313
+ let ( id, name) = item_ty_to_strs ( ItemType :: Import ) ;
2314
+ sidebar. push_str ( & format ! ( "<li><a href=\" #{}\" >{}</a></li>" , id, name) ) ;
2318
2315
}
2319
2316
2320
2317
// ordering taken from item_module, reorder, where it prioritized elements in a certain order
@@ -2341,13 +2338,9 @@ fn sidebar_module(buf: &mut Buffer, items: &[clean::Item]) {
2341
2338
ItemType :: ForeignType ,
2342
2339
ItemType :: Keyword ,
2343
2340
] {
2344
- if items. iter ( ) . any ( |it| !it. is_stripped ( ) && it. type_ ( ) == myty) {
2345
- let ( short, name) = item_ty_to_strs ( & myty) ;
2346
- sidebar. push_str ( & format ! (
2347
- "<li><a href=\" #{id}\" >{name}</a></li>" ,
2348
- id = short,
2349
- name = name
2350
- ) ) ;
2341
+ if items. iter ( ) . any ( |it| !it. is_stripped ( ) && it. type_ ( ) == myty && it. name . is_some ( ) ) {
2342
+ let ( id, name) = item_ty_to_strs ( myty) ;
2343
+ sidebar. push_str ( & format ! ( "<li><a href=\" #{}\" >{}</a></li>" , id, name) ) ;
2351
2344
}
2352
2345
}
2353
2346
0 commit comments