From 61d0365aacbf9c2729d78032e88138d07e5f15bb Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 7 Apr 2015 16:18:49 -0700 Subject: [PATCH] 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 --- src/librustdoc/clean/inline.rs | 9 +++++++-- src/test/auxiliary/issue-23207-1.rs | 13 +++++++++++++ src/test/auxiliary/issue-23207-2.rs | 16 ++++++++++++++++ src/test/rustdoc/issue-23207.rs | 19 +++++++++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/test/auxiliary/issue-23207-1.rs create mode 100644 src/test/auxiliary/issue-23207-2.rs create mode 100644 src/test/rustdoc/issue-23207.rs diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 4237eb68d28..f14437b71b4 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -10,6 +10,8 @@ //! Support for inlining external documentation into the current AST. +use std::collections::HashSet; + use syntax::ast; use syntax::ast_util; use syntax::attr::AttrMetaMethods; @@ -400,16 +402,19 @@ fn build_module(cx: &DocContext, tcx: &ty::ctxt, is_crate: false, }; - // FIXME: this doesn't handle reexports inside the module itself. - // Should they be handled? fn fill_in(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId, items: &mut Vec) { + // If we're reexporting a reexport it may actually reexport something in + // two namespaces, so the target may be listed twice. Make sure we only + // visit each node at most once. + let mut visited = HashSet::new(); csearch::each_child_of_item(&tcx.sess.cstore, did, |def, _, vis| { match def { decoder::DlDef(def::DefForeignMod(did)) => { fill_in(cx, tcx, did, items); } decoder::DlDef(def) if vis == ast::Public => { + if !visited.insert(def) { return } match try_inline_def(cx, tcx, def) { Some(i) => items.extend(i.into_iter()), None => {} diff --git a/src/test/auxiliary/issue-23207-1.rs b/src/test/auxiliary/issue-23207-1.rs new file mode 100644 index 00000000000..ec9f2004ebf --- /dev/null +++ b/src/test/auxiliary/issue-23207-1.rs @@ -0,0 +1,13 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub mod fmt { + pub struct Error; +} diff --git a/src/test/auxiliary/issue-23207-2.rs b/src/test/auxiliary/issue-23207-2.rs new file mode 100644 index 00000000000..5e9c540ab69 --- /dev/null +++ b/src/test/auxiliary/issue-23207-2.rs @@ -0,0 +1,16 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern crate issue_23207_1; + +pub mod fmt { + pub use issue_23207_1::fmt::Error; +} + diff --git a/src/test/rustdoc/issue-23207.rs b/src/test/rustdoc/issue-23207.rs new file mode 100644 index 00000000000..a44a1dd8b2d --- /dev/null +++ b/src/test/rustdoc/issue-23207.rs @@ -0,0 +1,19 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:issue-23207-1.rs +// aux-build:issue-23207-2.rs + +extern crate issue_23207_2; + +// @has issue_23207/fmt/index.html +// @count - '//*[@class="struct"]' 1 +pub use issue_23207_2::fmt; +