Skip to content

Commit

Permalink
Rollup merge of rust-lang#99738 - notriddle:notriddle/multiple-module…
Browse files Browse the repository at this point in the history
…s-w-same-name, r=camelid

rustdoc: avoid inlining modules with duplicate names

Fixes rust-lang#99734
  • Loading branch information
Dylan-DPC authored Aug 3, 2022
2 parents cb9932e + 8724ca3 commit acf6912
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,24 @@ pub(crate) trait Clean<'tcx, T> {
impl<'tcx> Clean<'tcx, Item> for DocModule<'tcx> {
fn clean(&self, cx: &mut DocContext<'tcx>) -> Item {
let mut items: Vec<Item> = vec![];
items.extend(
self.foreigns
.iter()
.map(|(item, renamed)| clean_maybe_renamed_foreign_item(cx, item, *renamed)),
);
items.extend(self.mods.iter().map(|x| x.clean(cx)));
let mut inserted = FxHashSet::default();
items.extend(self.foreigns.iter().map(|(item, renamed)| {
let item = clean_maybe_renamed_foreign_item(cx, item, *renamed);
if let Some(name) = item.name {
inserted.insert((item.type_(), name));
}
item
}));
items.extend(self.mods.iter().map(|x| {
inserted.insert((ItemType::Module, x.name));
x.clean(cx)
}));

// Split up imports from all other items.
//
// This covers the case where somebody does an import which should pull in an item,
// but there's already an item with the same namespace and same name. Rust gives
// priority to the not-imported one, so we should, too.
let mut inserted = FxHashSet::default();
items.extend(self.items.iter().flat_map(|(item, renamed)| {
// First, lower everything other than imports.
if matches!(item.kind, hir::ItemKind::Use(..)) {
Expand Down
11 changes: 11 additions & 0 deletions src/test/rustdoc/auxiliary/issue-99734-aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub struct Option;
impl Option {
pub fn unwrap(self) {}
}

/// [`Option::unwrap`]
pub mod task {}

extern "C" {
pub fn main() -> std::ffi::c_int;
}
16 changes: 16 additions & 0 deletions src/test/rustdoc/issue-99734-multiple-foreigns-w-same-name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// aux-build:issue-99734-aux.rs
// build-aux-docs
// ignore-cross-compile

#![crate_name = "foo"]

#[macro_use]
extern crate issue_99734_aux;

pub use issue_99734_aux::*;

// @count foo/index.html '//a[@class="fn"][@title="foo::main fn"]' 1

extern "C" {
pub fn main() -> std::ffi::c_int;
}
14 changes: 14 additions & 0 deletions src/test/rustdoc/issue-99734-multiple-mods-w-same-name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// aux-build:issue-99734-aux.rs
// build-aux-docs
// ignore-cross-compile

#![crate_name = "foo"]

#[macro_use]
extern crate issue_99734_aux;

pub use issue_99734_aux::*;

// @count foo/index.html '//a[@class="mod"][@title="foo::task mod"]' 1

pub mod task {}

0 comments on commit acf6912

Please sign in to comment.