From 68ccba81aea7f4ae86c97d88a6d7a3ea3f758f7e Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Mon, 12 Jun 2017 19:00:09 +0100 Subject: [PATCH] rustdoc: Fix missing enum variant reexports --- src/librustdoc/clean/inline.rs | 8 ++++---- src/librustdoc/visit_ast.rs | 24 ++++++++++-------------- src/test/rustdoc/issue-35488.rs | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 src/test/rustdoc/issue-35488.rs diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 8f7add14d0a..e617402d8db 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -77,10 +77,10 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name) ret.extend(build_impls(cx, did)); clean::EnumItem(build_enum(cx, did)) } - // Assume that the enum type is reexported next to the variant, and - // variants don't show up in documentation specially. - // Similarly, consider that struct type is reexported next to its constructor. - Def::Variant(..) | + // Never inline enum variants but leave them shown as reexports. + Def::Variant(..) => return None, + // Assume that enum variants and struct types are reexported next to + // their constructors. Def::VariantCtor(..) | Def::StructCtor(..) => return Some(Vec::new()), Def::Mod(did) => { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 39ebe490d0e..657aab958bb 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -329,25 +329,21 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { if !self.view_item_stack.insert(def_node_id) { return false } let ret = match tcx.hir.get(def_node_id) { - hir_map::NodeItem(it) => { + hir_map::NodeItem(&hir::Item { node: hir::ItemMod(ref m), .. }) if glob => { let prev = mem::replace(&mut self.inlining, true); - if glob { - match it.node { - hir::ItemMod(ref m) => { - for i in &m.item_ids { - let i = self.cx.tcx.hir.expect_item(i.id); - self.visit_item(i, None, om); - } - } - hir::ItemEnum(..) => {} - _ => { panic!("glob not mapped to a module or enum"); } - } - } else { - self.visit_item(it, renamed, om); + for i in &m.item_ids { + let i = self.cx.tcx.hir.expect_item(i.id); + self.visit_item(i, None, om); } self.inlining = prev; true } + hir_map::NodeItem(it) if !glob => { + let prev = mem::replace(&mut self.inlining, true); + self.visit_item(it, renamed, om); + self.inlining = prev; + true + } _ => false, }; self.view_item_stack.remove(&def_node_id); diff --git a/src/test/rustdoc/issue-35488.rs b/src/test/rustdoc/issue-35488.rs new file mode 100644 index 00000000000..f24166a65f0 --- /dev/null +++ b/src/test/rustdoc/issue-35488.rs @@ -0,0 +1,23 @@ +// Copyright 2017 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. + +mod foo { + pub enum Foo { + Bar, + } + pub use self::Foo::*; +} + +// @has 'issue_35488/index.html' '//code' 'pub use self::Foo::*;' +// @has 'issue_35488/enum.Foo.html' +pub use self::foo::*; + +// @has 'issue_35488/index.html' '//code' 'pub use std::option::Option::None;' +pub use std::option::Option::None;