Skip to content

Commit 968f306

Browse files
authored
Rollup merge of rust-lang#94002 - GuillaumeGomez:duplicated-sidebar-macro, r=notriddle
rustdoc: Avoid duplicating macros in sidebar Fixes rust-lang#93912. cc `@jsha` (for the GUI test) r? `@camelid`
2 parents 188a292 + d9ea7bc commit 968f306

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

src/librustdoc/html/render/context.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ impl<'tcx> Context<'tcx> {
250250
fn build_sidebar_items(&self, m: &clean::Module) -> BTreeMap<String, Vec<NameDoc>> {
251251
// BTreeMap instead of HashMap to get a sorted output
252252
let mut map: BTreeMap<_, Vec<_>> = BTreeMap::new();
253+
let mut inserted: FxHashMap<ItemType, FxHashSet<Symbol>> = FxHashMap::default();
254+
253255
for item in &m.items {
254256
if item.is_stripped() {
255257
continue;
@@ -258,13 +260,16 @@ impl<'tcx> Context<'tcx> {
258260
let short = item.type_();
259261
let myname = match item.name {
260262
None => continue,
261-
Some(ref s) => s.to_string(),
263+
Some(s) => s,
262264
};
263-
let short = short.to_string();
264-
map.entry(short).or_default().push((
265-
myname,
266-
Some(item.doc_value().map_or_else(String::new, |s| plain_text_summary(&s))),
267-
));
265+
if inserted.entry(short).or_default().insert(myname) {
266+
let short = short.to_string();
267+
let myname = myname.to_string();
268+
map.entry(short).or_default().push((
269+
myname,
270+
Some(item.doc_value().map_or_else(String::new, |s| plain_text_summary(&s))),
271+
));
272+
}
268273
}
269274

270275
if self.shared.sort_modules_alphabetically {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This test ensures that there is no macro duplicates in the sidebar.
2+
goto: file://|DOC_PATH|/test_docs/macro.a.html
3+
// Waiting for the elements in the sidebar to be rendered.
4+
wait-for: ".sidebar-elems .others .macro"
5+
// Check there is only one macro named "a" listed in the sidebar.
6+
assert-count: (
7+
"//*[@class='sidebar-elems']//*[@class='others']/*[@class='block macro']//li/a[text()='a']",
8+
1,
9+
)
10+
// Check there is only one macro named "b" listed in the sidebar.
11+
assert-count: (
12+
"//*[@class='sidebar-elems']//*[@class='others']/*[@class='block macro']//li/a[text()='b']",
13+
1,
14+
)

src/test/rustdoc-gui/src/test_docs/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,6 @@ impl EmptyTrait1 for HasEmptyTraits {}
271271
impl EmptyTrait2 for HasEmptyTraits {}
272272
#[doc(cfg(feature = "some-feature"))]
273273
impl EmptyTrait3 for HasEmptyTraits {}
274+
275+
mod macros;
276+
pub use macros::*;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[macro_export]
2+
macro_rules! a{ () => {}}
3+
#[macro_export]
4+
macro_rules! b{ () => {}}

0 commit comments

Comments
 (0)