diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2022-06-29 13:04:43 -0700 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2022-06-29 13:04:43 -0700 |
| commit | be0b1121e9ede0cc3b322aba8d8a2a9bb48572f6 (patch) | |
| tree | e1b34d27b190490ea8e3cd1ea27f0862be3bae08 /src/librustdoc/html/render | |
| parent | 3fcf43bb0f3e86c16a88f239da18a1729a94d244 (diff) | |
| download | rust-be0b1121e9ede0cc3b322aba8d8a2a9bb48572f6.tar.gz rust-be0b1121e9ede0cc3b322aba8d8a2a9bb48572f6.zip | |
Replace `sort_modules_alphabetically` boolean with enum
This fixes the long-standing FIXME there and makes the code easier to understand. The reference to modules in both the old and new names seems potentially wrong since I believe it applies to all items.
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/context.rs | 17 | ||||
| -rw-r--r-- | src/librustdoc/html/render/print_item.rs | 8 |
2 files changed, 16 insertions, 9 deletions
diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index bfdc44c7e45..2ed7a6f1bb1 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -22,7 +22,7 @@ use super::{ }; use crate::clean::{self, types::ExternalLocation, ExternalCrate}; -use crate::config::RenderOptions; +use crate::config::{ModuleSorting, RenderOptions}; use crate::docfs::{DocFS, PathError}; use crate::error::Error; use crate::formats::cache::Cache; @@ -95,7 +95,7 @@ pub(crate) struct SharedContext<'tcx> { created_dirs: RefCell<FxHashSet<PathBuf>>, /// This flag indicates whether listings of modules (in the side bar and documentation itself) /// should be ordered alphabetically or in order of appearance (in the source code). - pub(super) sort_modules_alphabetically: bool, + pub(super) module_sorting: ModuleSorting, /// Additional CSS files to be added to the generated docs. pub(crate) style_files: Vec<StylePath>, /// Suffix to be added on resource files (if suffix is "-v2" then "light.css" becomes @@ -280,10 +280,13 @@ impl<'tcx> Context<'tcx> { } } - if self.shared.sort_modules_alphabetically { - for items in map.values_mut() { - items.sort(); + match self.shared.module_sorting { + ModuleSorting::Alphabetical => { + for items in map.values_mut() { + items.sort(); + } } + ModuleSorting::DeclarationOrder => {} } map } @@ -394,7 +397,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { external_html, id_map, playground_url, - sort_modules_alphabetically, + module_sorting, themes: style_files, default_settings, extension_css, @@ -476,7 +479,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { issue_tracker_base_url, layout, created_dirs: Default::default(), - sort_modules_alphabetically, + module_sorting, style_files, resource_suffix, static_root_path, diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index d115185562c..0fe99463f1d 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -23,6 +23,7 @@ use super::{ AssocItemLink, Context, ImplRenderingParameters, }; use crate::clean; +use crate::config::ModuleSorting; use crate::formats::item_type::ItemType; use crate::formats::{AssocItemRender, Impl, RenderMode}; use crate::html::escape::Escape; @@ -246,8 +247,11 @@ fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: compare_names(lhs.as_str(), rhs.as_str()) } - if cx.shared.sort_modules_alphabetically { - indices.sort_by(|&i1, &i2| cmp(&items[i1], &items[i2], i1, i2, cx.tcx())); + match cx.shared.module_sorting { + ModuleSorting::Alphabetical => { + indices.sort_by(|&i1, &i2| cmp(&items[i1], &items[i2], i1, i2, cx.tcx())); + } + ModuleSorting::DeclarationOrder => {} } // This call is to remove re-export duplicates in cases such as: // |
