Skip to content

Commit 61d0365

Browse files
committed
rustdoc: Handle duplicate reexports listed
This ends up causing duplicate output in rustdoc. The source of these duplicates is that the item is defined in both resolve namespaces, so it's listed twice. Closes #23207
1 parent dbaa242 commit 61d0365

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

src/librustdoc/clean/inline.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
//! Support for inlining external documentation into the current AST.
1212
13+
use std::collections::HashSet;
14+
1315
use syntax::ast;
1416
use syntax::ast_util;
1517
use syntax::attr::AttrMetaMethods;
@@ -400,16 +402,19 @@ fn build_module(cx: &DocContext, tcx: &ty::ctxt,
400402
is_crate: false,
401403
};
402404

403-
// FIXME: this doesn't handle reexports inside the module itself.
404-
// Should they be handled?
405405
fn fill_in(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId,
406406
items: &mut Vec<clean::Item>) {
407+
// If we're reexporting a reexport it may actually reexport something in
408+
// two namespaces, so the target may be listed twice. Make sure we only
409+
// visit each node at most once.
410+
let mut visited = HashSet::new();
407411
csearch::each_child_of_item(&tcx.sess.cstore, did, |def, _, vis| {
408412
match def {
409413
decoder::DlDef(def::DefForeignMod(did)) => {
410414
fill_in(cx, tcx, did, items);
411415
}
412416
decoder::DlDef(def) if vis == ast::Public => {
417+
if !visited.insert(def) { return }
413418
match try_inline_def(cx, tcx, def) {
414419
Some(i) => items.extend(i.into_iter()),
415420
None => {}

src/test/auxiliary/issue-23207-1.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub mod fmt {
12+
pub struct Error;
13+
}

src/test/auxiliary/issue-23207-2.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
extern crate issue_23207_1;
12+
13+
pub mod fmt {
14+
pub use issue_23207_1::fmt::Error;
15+
}
16+

src/test/rustdoc/issue-23207.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:issue-23207-1.rs
12+
// aux-build:issue-23207-2.rs
13+
14+
extern crate issue_23207_2;
15+
16+
// @has issue_23207/fmt/index.html
17+
// @count - '//*[@class="struct"]' 1
18+
pub use issue_23207_2::fmt;
19+

0 commit comments

Comments
 (0)