Skip to content

Commit 68ccba8

Browse files
committed
rustdoc: Fix missing enum variant reexports
1 parent 19193d6 commit 68ccba8

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ pub fn try_inline(cx: &DocContext, def: Def, name: ast::Name)
7777
ret.extend(build_impls(cx, did));
7878
clean::EnumItem(build_enum(cx, did))
7979
}
80-
// Assume that the enum type is reexported next to the variant, and
81-
// variants don't show up in documentation specially.
82-
// Similarly, consider that struct type is reexported next to its constructor.
83-
Def::Variant(..) |
80+
// Never inline enum variants but leave them shown as reexports.
81+
Def::Variant(..) => return None,
82+
// Assume that enum variants and struct types are reexported next to
83+
// their constructors.
8484
Def::VariantCtor(..) |
8585
Def::StructCtor(..) => return Some(Vec::new()),
8686
Def::Mod(did) => {

src/librustdoc/visit_ast.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -329,25 +329,21 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
329329
if !self.view_item_stack.insert(def_node_id) { return false }
330330

331331
let ret = match tcx.hir.get(def_node_id) {
332-
hir_map::NodeItem(it) => {
332+
hir_map::NodeItem(&hir::Item { node: hir::ItemMod(ref m), .. }) if glob => {
333333
let prev = mem::replace(&mut self.inlining, true);
334-
if glob {
335-
match it.node {
336-
hir::ItemMod(ref m) => {
337-
for i in &m.item_ids {
338-
let i = self.cx.tcx.hir.expect_item(i.id);
339-
self.visit_item(i, None, om);
340-
}
341-
}
342-
hir::ItemEnum(..) => {}
343-
_ => { panic!("glob not mapped to a module or enum"); }
344-
}
345-
} else {
346-
self.visit_item(it, renamed, om);
334+
for i in &m.item_ids {
335+
let i = self.cx.tcx.hir.expect_item(i.id);
336+
self.visit_item(i, None, om);
347337
}
348338
self.inlining = prev;
349339
true
350340
}
341+
hir_map::NodeItem(it) if !glob => {
342+
let prev = mem::replace(&mut self.inlining, true);
343+
self.visit_item(it, renamed, om);
344+
self.inlining = prev;
345+
true
346+
}
351347
_ => false,
352348
};
353349
self.view_item_stack.remove(&def_node_id);

src/test/rustdoc/issue-35488.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2017 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+
mod foo {
12+
pub enum Foo {
13+
Bar,
14+
}
15+
pub use self::Foo::*;
16+
}
17+
18+
// @has 'issue_35488/index.html' '//code' 'pub use self::Foo::*;'
19+
// @has 'issue_35488/enum.Foo.html'
20+
pub use self::foo::*;
21+
22+
// @has 'issue_35488/index.html' '//code' 'pub use std::option::Option::None;'
23+
pub use std::option::Option::None;

0 commit comments

Comments
 (0)