Skip to content

Commit

Permalink
Rollup merge of rust-lang#46412 - chrisduerr:issue-46380, r=QuietMisd…
Browse files Browse the repository at this point in the history
…reavus

Hide private trait type params and show hidden items with document-private

As discussed in rust-lang#46380, this PR removes the `strip-hidden` pass from `--document-private-items` which allows showing `#[doc(hidden)]` with rustdoc.

The second commit removes the trait implementation from the docs if the trait's parameter is private.
  • Loading branch information
kennytm authored Dec 1, 2017
2 parents 3f99b7c + 5f47c7f commit 662f902
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
];
Expand Down
9 changes: 9 additions & 0 deletions src/librustdoc/passes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/rustdoc/issue-46380-2.rs
Original file line number Diff line number Diff line change
@@ -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 <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.

pub trait PublicTrait<T> {}

// @has issue_46380_2/struct.PublicStruct.html
pub struct PublicStruct;

// @!has - '//*[@class="impl"]' 'impl PublicTrait<PrivateStruct> for PublicStruct'
impl PublicTrait<PrivateStruct> for PublicStruct {}

struct PrivateStruct;
15 changes: 15 additions & 0 deletions src/test/rustdoc/issue-46380.rs
Original file line number Diff line number Diff line change
@@ -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 <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.

// compile-flags: --document-private-items

// @has issue_46380/struct.Hidden.html
#[doc(hidden)]
pub struct Hidden;

0 comments on commit 662f902

Please sign in to comment.