diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-02-20 00:55:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-20 00:55:12 +0100 |
| commit | 8ccfd06e46881701f7ddd500bb45d71a97ecdb59 (patch) | |
| tree | bac982c9f992d04fb78ac188dc2f0a2ad452295c /src/librustdoc/html/render | |
| parent | 6055793062ce470e2e6ad334b04d4bac0151f400 (diff) | |
| parent | a467ecacd4e77a3704924f5ac46f8a752e1e73e5 (diff) | |
| download | rust-8ccfd06e46881701f7ddd500bb45d71a97ecdb59.tar.gz rust-8ccfd06e46881701f7ddd500bb45d71a97ecdb59.zip | |
Rollup merge of #137106 - chenyukang:yukang-fix-sidebar-sort, r=notriddle
Add customized compare for Link in rustdoc Maybe some other types in sidebar need to be sorted in this way, maybe add this crate `natord` is ok? r? clubby789 Fixes #137098
Diffstat (limited to 'src/librustdoc/html/render')
| -rw-r--r-- | src/librustdoc/html/render/sidebar.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index 50c09b98db4..64dbaf9083e 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -1,4 +1,5 @@ use std::borrow::Cow; +use std::cmp::Ordering; use rinja::Template; use rustc_data_structures::fx::FxHashSet; @@ -12,6 +13,7 @@ use crate::clean; use crate::formats::Impl; use crate::formats::item_type::ItemType; use crate::html::markdown::{IdMap, MarkdownWithToc}; +use crate::html::render::print_item::compare_names; #[derive(Clone, Copy)] pub(crate) enum ModuleLike { @@ -77,7 +79,7 @@ impl<'a> LinkBlock<'a> { } /// A link to an item. Content should not be escaped. -#[derive(PartialOrd, Ord, PartialEq, Eq, Hash, Clone)] +#[derive(Ord, PartialEq, Eq, Hash, Clone)] pub(crate) struct Link<'a> { /// The content for the anchor tag and title attr name: Cow<'a, str>, @@ -89,6 +91,20 @@ pub(crate) struct Link<'a> { children: Vec<Link<'a>>, } +impl PartialOrd for Link<'_> { + fn partial_cmp(&self, other: &Link<'_>) -> Option<Ordering> { + match compare_names(&self.name, &other.name) { + Ordering::Equal => (), + result => return Some(result), + } + (&self.name_html, &self.href, &self.children).partial_cmp(&( + &other.name_html, + &other.href, + &other.children, + )) + } +} + impl<'a> Link<'a> { pub fn new(href: impl Into<Cow<'a, str>>, name: impl Into<Cow<'a, str>>) -> Self { Self { href: href.into(), name: name.into(), children: vec![], name_html: None } |
