From ec337b613ec5519a54f2948f9d8b7beea5cba86b Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 30 Nov 2017 21:18:00 +0100 Subject: [PATCH 1/3] Show hidden items with rustdoc's document-private When using `#[doc(hidden)]` elements are hidden from docs even when the rustdoc flag `--document-private-items` is set. This behavior has been changed to display all hidden items when the flag is active. --- src/librustdoc/lib.rs | 1 - src/test/rustdoc/issue-46380.rs | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc/issue-46380.rs diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index fcb25f7aef3d4..967076779add0 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -470,7 +470,6 @@ where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R { default_passes = false; passes = vec![ - String::from("strip-hidden"), String::from("collapse-docs"), String::from("unindent-comments"), ]; diff --git a/src/test/rustdoc/issue-46380.rs b/src/test/rustdoc/issue-46380.rs new file mode 100644 index 0000000000000..85f29ec4b02d1 --- /dev/null +++ b/src/test/rustdoc/issue-46380.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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. + +// compile-flags: --document-private-items + +// @has issue_46380/struct.Hidden.html +#[doc(hidden)] +pub struct Hidden; From 1df13c057a7f1937170fe600d24256f0bf943ec2 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 30 Nov 2017 21:18:36 +0100 Subject: [PATCH 2/3] Hide trait impl with private trait type parameter Trait's implementations with private type parameters were displayed in the implementing struct's documentation until now. With this change any trait implementation that uses a private type parameter is now hidden in the docs. --- src/librustdoc/passes/mod.rs | 9 +++++++++ src/test/rustdoc/issue-46380-2.rs | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/test/rustdoc/issue-46380-2.rs diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index 77d97c84c99bf..3e15d3d3007ac 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -184,6 +184,15 @@ impl<'a> fold::DocFolder for ImplStripper<'a> { return None; } } + if let Some(generics) = imp.trait_.as_ref().and_then(|t| t.generics()) { + for typaram in generics { + if let Some(did) = typaram.def_id() { + if did.is_local() && !self.retained.contains(&did) { + return None; + } + } + } + } } self.fold_item_recur(i) } diff --git a/src/test/rustdoc/issue-46380-2.rs b/src/test/rustdoc/issue-46380-2.rs new file mode 100644 index 0000000000000..93a1ee72013c3 --- /dev/null +++ b/src/test/rustdoc/issue-46380-2.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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. + +pub trait PublicTrait {} + +// @has issue_46380_2/struct.Public.html +pub struct PublicStruct; + +// @!has - '//*[@class="impl"]' 'impl Add for Public' +impl PublicTrait for PublicStruct {} + +struct PrivateStruct; From 5f47c7f531a4a93a563e02a0d5206c5c7139801f Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 30 Nov 2017 21:43:21 +0100 Subject: [PATCH 3/3] Fix htmldocck naming After renaming the structs and enums the htmldocck strings still contained the old names. This lead to test failure. These htmldocck tests have been updated to use the proper names of the rust structs and traits. --- src/test/rustdoc/issue-46380-2.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/rustdoc/issue-46380-2.rs b/src/test/rustdoc/issue-46380-2.rs index 93a1ee72013c3..22408d3522a4b 100644 --- a/src/test/rustdoc/issue-46380-2.rs +++ b/src/test/rustdoc/issue-46380-2.rs @@ -10,10 +10,10 @@ pub trait PublicTrait {} -// @has issue_46380_2/struct.Public.html +// @has issue_46380_2/struct.PublicStruct.html pub struct PublicStruct; -// @!has - '//*[@class="impl"]' 'impl Add for Public' +// @!has - '//*[@class="impl"]' 'impl PublicTrait for PublicStruct' impl PublicTrait for PublicStruct {} struct PrivateStruct;