about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Middleton <olliemail27@gmail.com>2018-07-10 00:16:18 +0100
committerOliver Middleton <olliemail27@gmail.com>2018-07-10 00:16:18 +0100
commit6b1d584ed8b208ef02dc234f67c99d8bed7dd33e (patch)
tree7ccd1390b9647adb4db3d2ff66a362bdcdc18ef3
parentc6807bb1b282e0c5398aa4e659dbc165b6f3c81b (diff)
downloadrust-6b1d584ed8b208ef02dc234f67c99d8bed7dd33e.tar.gz
rust-6b1d584ed8b208ef02dc234f67c99d8bed7dd33e.zip
rustdoc: Hide struct and enum variant constructor imports
-rw-r--r--src/librustdoc/visit_ast.rs12
-rw-r--r--src/test/rustdoc/constructor-imports.rs25
2 files changed, 32 insertions, 5 deletions
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs
index 2fb69b2cee0..b7a9f95fdc0 100644
--- a/src/librustdoc/visit_ast.rs
+++ b/src/librustdoc/visit_ast.rs
@@ -323,11 +323,6 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
                 });
                 true
             }
-            hir_map::NodeStructCtor(_) if !glob => {
-                // struct constructors always show up alongside their struct definitions, we've
-                // already processed that so just discard this
-                true
-            }
             _ => false,
         };
         self.view_item_stack.remove(&def_node_id);
@@ -375,6 +370,13 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
             hir::ItemUse(ref path, kind) => {
                 let is_glob = kind == hir::UseKind::Glob;
 
+                // struct and variant constructors always show up alongside their definitions, we've
+                // already processed them so just discard these.
+                match path.def {
+                    Def::StructCtor(..) | Def::VariantCtor(..) => return,
+                    _ => {}
+                }
+
                 // If there was a private module in the current path then don't bother inlining
                 // anything as it will probably be stripped anyway.
                 if item.vis.node.is_pub() && self.inside_public_path {
diff --git a/src/test/rustdoc/constructor-imports.rs b/src/test/rustdoc/constructor-imports.rs
new file mode 100644
index 00000000000..c170eadd3c6
--- /dev/null
+++ b/src/test/rustdoc/constructor-imports.rs
@@ -0,0 +1,25 @@
+// Copyright 2018 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.
+
+#![crate_name = "foo"]
+
+pub mod a {
+    pub struct Foo;
+    pub enum Bar {
+        Baz,
+    }
+}
+
+// @count 'foo/index.html' '//*[code="pub use a::Foo;"]' 1
+#[doc(no_inline)]
+pub use a::Foo;
+// @count 'foo/index.html' '//*[code="pub use a::Bar::Baz;"]' 1
+#[doc(no_inline)]
+pub use a::Bar::Baz;