Skip to content

Commit 225ac9e

Browse files
committed
rustdoc: avoid inlining modules with duplicate names
Fixes #99734
1 parent bdf520f commit 225ac9e

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/librustdoc/clean/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,22 @@ pub(crate) trait Clean<'tcx, T> {
5151
impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
5252
fn clean(&self, cx: &mut DocContext<'tcx>) -> Item {
5353
let mut items: Vec<Item> = vec![];
54+
let mut inserted = FxHashSet::default();
5455
items.extend(
5556
self.foreigns
5657
.iter()
5758
.map(|(item, renamed)| clean_maybe_renamed_foreign_item(cx, item, *renamed)),
5859
);
59-
items.extend(self.mods.iter().map(|x| x.clean(cx)));
60+
items.extend(self.mods.iter().map(|x| {
61+
inserted.insert((ItemType::Module, x.name));
62+
x.clean(cx)
63+
}));
6064

6165
// Split up imports from all other items.
6266
//
6367
// This covers the case where somebody does an import which should pull in an item,
6468
// but there's already an item with the same namespace and same name. Rust gives
6569
// priority to the not-imported one, so we should, too.
66-
let mut inserted = FxHashSet::default();
6770
items.extend(self.items.iter().flat_map(|(item, renamed)| {
6871
// First, lower everything other than imports.
6972
if matches!(item.kind, hir::ItemKind::Use(..)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub struct Option;
2+
impl Option {
3+
pub fn unwrap(self) {}
4+
}
5+
6+
/// [`Option::unwrap`]
7+
pub mod task {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// aux-build:issue-99734-aux.rs
2+
// build-aux-docs
3+
// ignore-cross-compile
4+
5+
#![crate_name = "foo"]
6+
7+
#[macro_use]
8+
extern crate issue_99734_aux;
9+
10+
pub use issue_99734_aux::*;
11+
12+
// @count foo/index.html '//a[@class="mod"][@title="foo::task mod"]' 1
13+
14+
pub mod task {}

0 commit comments

Comments
 (0)