Rollup merge of #94002 - GuillaumeGomez:duplicated-sidebar-macro, r=notriddle
rustdoc: Avoid duplicating macros in sidebar Fixes #93912. cc ``````@jsha`````` (for the GUI test) r? ``````@camelid``````
This commit is contained in:
commit
1ae00e0b93
4 changed files with 32 additions and 6 deletions
|
@ -250,6 +250,8 @@ impl<'tcx> Context<'tcx> {
|
||||||
fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc>> {
|
fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc>> {
|
||||||
// BTreeMap instead of HashMap to get a sorted output
|
// BTreeMap instead of HashMap to get a sorted output
|
||||||
let mut map: BTreeMap<_, Vec<_>> = BTreeMap::new();
|
let mut map: BTreeMap<_, Vec<_>> = BTreeMap::new();
|
||||||
|
let mut inserted: FxHashMap<ItemType, FxHashSet<Symbol>> = FxHashMap::default();
|
||||||
|
|
||||||
for item in &m.items {
|
for item in &m.items {
|
||||||
if item.is_stripped() {
|
if item.is_stripped() {
|
||||||
continue;
|
continue;
|
||||||
|
@ -258,14 +260,17 @@ impl<'tcx> Context<'tcx> {
|
||||||
let short = item.type_();
|
let short = item.type_();
|
||||||
let myname = match item.name {
|
let myname = match item.name {
|
||||||
None => continue,
|
None => continue,
|
||||||
Some(ref s) => s.to_string(),
|
Some(s) => s,
|
||||||
};
|
};
|
||||||
|
if inserted.entry(short).or_default().insert(myname) {
|
||||||
let short = short.to_string();
|
let short = short.to_string();
|
||||||
|
let myname = myname.to_string();
|
||||||
map.entry(short).or_default().push((
|
map.entry(short).or_default().push((
|
||||||
myname,
|
myname,
|
||||||
Some(item.doc_value().map_or_else(String::new, |s| plain_text_summary(&s))),
|
Some(item.doc_value().map_or_else(String::new, |s| plain_text_summary(&s))),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if self.shared.sort_modules_alphabetically {
|
if self.shared.sort_modules_alphabetically {
|
||||||
for items in map.values_mut() {
|
for items in map.values_mut() {
|
||||||
|
|
14
src/test/rustdoc-gui/duplicate-macro-reexport.goml
Normal file
14
src/test/rustdoc-gui/duplicate-macro-reexport.goml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// This test ensures that there is no macro duplicates in the sidebar.
|
||||||
|
goto: file://|DOC_PATH|/test_docs/macro.a.html
|
||||||
|
// Waiting for the elements in the sidebar to be rendered.
|
||||||
|
wait-for: ".sidebar-elems .others .macro"
|
||||||
|
// Check there is only one macro named "a" listed in the sidebar.
|
||||||
|
assert-count: (
|
||||||
|
"//*[@class='sidebar-elems']//*[@class='others']/*[@class='block macro']//li/a[text()='a']",
|
||||||
|
1,
|
||||||
|
)
|
||||||
|
// Check there is only one macro named "b" listed in the sidebar.
|
||||||
|
assert-count: (
|
||||||
|
"//*[@class='sidebar-elems']//*[@class='others']/*[@class='block macro']//li/a[text()='b']",
|
||||||
|
1,
|
||||||
|
)
|
|
@ -271,3 +271,6 @@ impl EmptyTrait1 for HasEmptyTraits {}
|
||||||
impl EmptyTrait2 for HasEmptyTraits {}
|
impl EmptyTrait2 for HasEmptyTraits {}
|
||||||
#[doc(cfg(feature = "some-feature"))]
|
#[doc(cfg(feature = "some-feature"))]
|
||||||
impl EmptyTrait3 for HasEmptyTraits {}
|
impl EmptyTrait3 for HasEmptyTraits {}
|
||||||
|
|
||||||
|
mod macros;
|
||||||
|
pub use macros::*;
|
||||||
|
|
4
src/test/rustdoc-gui/src/test_docs/macros.rs
Normal file
4
src/test/rustdoc-gui/src/test_docs/macros.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! a{ () => {}}
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! b{ () => {}}
|
Loading…
Add table
Add a link
Reference in a new issue