Skip to content

Commit acf6912

Browse files
authored
Rollup merge of rust-lang#99738 - notriddle:notriddle/multiple-modules-w-same-name, r=camelid
rustdoc: avoid inlining modules with duplicate names Fixes rust-lang#99734
2 parents cb9932e + 8724ca3 commit acf6912

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

src/librustdoc/clean/mod.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,24 @@ 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-
items.extend(
55-
self.foreigns
56-
.iter()
57-
.map(|(item, renamed)| clean_maybe_renamed_foreign_item(cx, item, *renamed)),
58-
);
59-
items.extend(self.mods.iter().map(|x| x.clean(cx)));
54+
let mut inserted = FxHashSet::default();
55+
items.extend(self.foreigns.iter().map(|(item, renamed)| {
56+
let item = clean_maybe_renamed_foreign_item(cx, item, *renamed);
57+
if let Some(name) = item.name {
58+
inserted.insert((item.type_(), name));
59+
}
60+
item
61+
}));
62+
items.extend(self.mods.iter().map(|x| {
63+
inserted.insert((ItemType::Module, x.name));
64+
x.clean(cx)
65+
}));
6066

6167
// Split up imports from all other items.
6268
//
6369
// This covers the case where somebody does an import which should pull in an item,
6470
// but there's already an item with the same namespace and same name. Rust gives
6571
// priority to the not-imported one, so we should, too.
66-
let mut inserted = FxHashSet::default();
6772
items.extend(self.items.iter().flat_map(|(item, renamed)| {
6873
// First, lower everything other than imports.
6974
if matches!(item.kind, hir::ItemKind::Use(..)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub struct Option;
2+
impl Option {
3+
pub fn unwrap(self) {}
4+
}
5+
6+
/// [`Option::unwrap`]
7+
pub mod task {}
8+
9+
extern "C" {
10+
pub fn main() -> std::ffi::c_int;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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="fn"][@title="foo::main fn"]' 1
13+
14+
extern "C" {
15+
pub fn main() -> std::ffi::c_int;
16+
}
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)