Skip to content

rustdoc: Fix missing enum variant reexports #42608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
24 changes: 10 additions & 14 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a couple reads to understand what was going on here, but just to straighten out my understanding: Reworking the match like this means that glob imports of enums will never be inlined, making them always appear as pub use SomeEnum::*;, whereas before they would be treated as they were inlined, but the variants would never be visited, leaving them completely undocumented? I haven't worked much with the AST crawling portion of rustdoc, but looking at the comments at the head of the function and the other change in clean/inline.rs, that's the impression I get from this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. In most cases already reexported enum variant appear as pub use SomeEnum::*; or pub use SomeEnum::Foo;, this PR fixes a couple of specific cases when they don't.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I see you pushed an update, but r=me pending travis.

}
} 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);
Expand Down
23 changes: 23 additions & 0 deletions src/test/rustdoc/issue-35488.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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;