@@ -129,6 +129,9 @@ pub struct SharedContext {
129
129
/// The directories that have already been created in this doc run. Used to reduce the number
130
130
/// of spurious `create_dir_all` calls.
131
131
pub created_dirs : RefCell < FxHashSet < PathBuf > > ,
132
+ /// This flag indicates whether listings of modules (in the side bar and documentation itself)
133
+ /// should be ordered alphabetically or in order of appearance (in the source code).
134
+ pub sort_modules_alphabetically : bool ,
132
135
}
133
136
134
137
impl SharedContext {
@@ -491,7 +494,8 @@ pub fn run(mut krate: clean::Crate,
491
494
passes : FxHashSet < String > ,
492
495
css_file_extension : Option < PathBuf > ,
493
496
renderinfo : RenderInfo ,
494
- render_type : RenderType ) -> Result < ( ) , Error > {
497
+ render_type : RenderType ,
498
+ sort_modules_alphabetically : bool ) -> Result < ( ) , Error > {
495
499
let src_root = match krate. src {
496
500
FileName :: Real ( ref p) => match p. parent ( ) {
497
501
Some ( p) => p. to_path_buf ( ) ,
@@ -514,6 +518,7 @@ pub fn run(mut krate: clean::Crate,
514
518
css_file_extension : css_file_extension. clone ( ) ,
515
519
markdown_warnings : RefCell :: new ( vec ! [ ] ) ,
516
520
created_dirs : RefCell :: new ( FxHashSet ( ) ) ,
521
+ sort_modules_alphabetically,
517
522
} ;
518
523
519
524
// If user passed in `--playground-url` arg, we fill in crate name here
@@ -1654,8 +1659,10 @@ impl Context {
1654
1659
. push ( ( myname, Some ( plain_summary_line ( item. doc_value ( ) ) ) ) ) ;
1655
1660
}
1656
1661
1657
- for ( _, items) in & mut map {
1658
- items. sort ( ) ;
1662
+ if self . shared . sort_modules_alphabetically {
1663
+ for ( _, items) in & mut map {
1664
+ items. sort ( ) ;
1665
+ }
1659
1666
}
1660
1667
map
1661
1668
}
@@ -2013,7 +2020,9 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
2013
2020
name_key ( lhs) . cmp ( & name_key ( rhs) )
2014
2021
}
2015
2022
2016
- indices. sort_by ( |& i1, & i2| cmp ( & items[ i1] , & items[ i2] , i1, i2) ) ;
2023
+ if cx. shared . sort_modules_alphabetically {
2024
+ indices. sort_by ( |& i1, & i2| cmp ( & items[ i1] , & items[ i2] , i1, i2) ) ;
2025
+ }
2017
2026
// This call is to remove reexport duplicates in cases such as:
2018
2027
//
2019
2028
// ```
0 commit comments