From 5ee3d0e1ffa6e190d73815ba4754b2618528c83e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 23 May 2014 19:01:33 -0700 Subject: [PATCH] rustdoc: Inline reexported modules --- src/librustdoc/clean.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index 79f687b0624..a78e9d1d1fb 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -1575,8 +1575,12 @@ fn try_inline(id: ast::NodeId) -> Option> { }; let did = ast_util::def_id_of_def(def); if ast_util::is_local(did) { return None } + try_inline_def(tcx, def) +} +fn try_inline_def(tcx: &ty::ctxt, def: ast::Def) -> Option> { let mut ret = Vec::new(); + let did = ast_util::def_id_of_def(def); let inner = match def { ast::DefTrait(did) => TraitItem(build_external_trait(tcx, did)), ast::DefFn(did, style) => @@ -1592,6 +1596,7 @@ fn try_inline(id: ast::NodeId) -> Option> { // Assume that the enum type is reexported next to the variant, and // variants don't show up in documentation specially. ast::DefVariant(..) => return Some(Vec::new()), + ast::DefMod(did) => ModuleItem(build_module(tcx, did)), _ => return None, }; let fqn = csearch::get_item_path(tcx, did); @@ -1995,6 +2000,28 @@ fn build_impl(tcx: &ty::ctxt, did: ast::DefId) -> Item { } } +fn build_module(tcx: &ty::ctxt, did: ast::DefId) -> Module { + let mut items = Vec::new(); + + csearch::each_child_of_item(&tcx.sess.cstore, did, |def, _, _| { + match def { + decoder::DlDef(def) => { + match try_inline_def(tcx, def) { + Some(i) => items.extend(i.move_iter()), + None => {} + } + } + decoder::DlImpl(did) => items.push(build_impl(tcx, did)), + decoder::DlField => fail!("unimplemented field"), + } + }); + + Module { + items: items, + is_crate: false, + } +} + fn resolve_use_source(path: Path, id: ast::NodeId) -> ImportSource { ImportSource { path: path,