Skip to content
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

Rustdoc: Do not list impl when trait has doc(hidden) #86513

Merged
merged 3 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
19 changes: 18 additions & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;

use crate::clean::{self, Attributes, AttributesExt, FakeDefId, GetDefId, ToSource};
use crate::clean::{
self, Attributes, AttributesExt, FakeDefId, GetDefId, NestedAttributesExt, ToSource, Type,
};
use crate::core::DocContext;
use crate::formats::item_type::ItemType;

Expand Down Expand Up @@ -420,6 +422,21 @@ crate fn build_impl(
if trait_.def_id() == tcx.lang_items().deref_trait() {
super::build_deref_target_impls(cx, &trait_items, ret);
}

// Return if the trait itself or any types of the generic parameters are doc(hidden).
let mut stack: Vec<&Type> = trait_.iter().collect();
stack.push(&for_);
while let Some(ty) = stack.pop() {
if let Some(did) = ty.def_id() {
if cx.tcx.get_attrs(did).lists(sym::doc).has_word(sym::hidden) {
return;
}
}
if let Some(generics) = ty.generics() {
stack.extend(generics);
}
}

if let Some(trait_did) = trait_.def_id() {
record_extern_trait(cx, trait_did);
}
Expand Down
5 changes: 5 additions & 0 deletions src/test/rustdoc/auxiliary/cross-crate-hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[doc(hidden)]
pub enum HiddenType {}

#[doc(hidden)]
pub trait HiddenTrait {}
35 changes: 35 additions & 0 deletions src/test/rustdoc/cross-crate-hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Issue #86448: test for cross-crate `doc(hidden)`
#![crate_name = "foo"]

// aux-build:cross-crate-hidden.rs
extern crate cross_crate_hidden;

pub use ::cross_crate_hidden::{HiddenType, HiddenTrait}; // OK, not re-exported
Copy link
Member

Choose a reason for hiding this comment

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

Can you also test this for the same-crate case?

Suggested change
// aux-build:cross-crate-hidden.rs
extern crate cross_crate_hidden;
pub use ::cross_crate_hidden::{HiddenType, HiddenTrait}; // OK, not re-exported
// revisions: extern local
// [extern] aux-build:cross-crate-hidden.rs
#[cfg(extern)]
extern crate cross_crate_hidden;
#[cfg(extern)]
pub use ::cross_crate_hidden::{HiddenType, HiddenTrait}; // OK, not re-exported
#[cfg(local)]
#[doc(hidden)]
pub enum HiddenType {}
#[cfg(local)]
#[doc(hidden)]
pub trait HiddenTrait {}

(not sure if revisions work for rustdoc tests - if not, it's fine to make these two separate tests.)

Please also change the file name from cross-crate-hidden to cross-crate-hidden-impl-parameter, which I think is a more accurate description.

Copy link
Member Author

@fee1-dead fee1-dead Jun 25, 2021

Choose a reason for hiding this comment

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

revisions do not work - I have added a separate test

@rustbot label -S-waiting-on-author S-waiting-on-review


pub enum MyLibType {}

// @!has foo/enum.MyLibType.html '//*[@id="impl-From%3CHiddenType%3E"]' 'impl From<HiddenType> for MyLibType'
impl From<HiddenType> for MyLibType {
fn from(it: HiddenType) -> MyLibType {
match it {}
}
}

pub struct T<T>(T);

// @!has foo/enum.MyLibType.html '//*[@id="impl-From%3CT%3CT%3CT%3CT%3CHiddenType%3E%3E%3E%3E%3E"]' 'impl From<T<T<T<T<HiddenType>>>>> for MyLibType'
impl From<T<T<T<T<HiddenType>>>>> for MyLibType {
fn from(it: T<T<T<T<HiddenType>>>>) -> MyLibType {
todo!()
}
}

// @!has foo/enum.MyLibType.html '//*[@id="impl-HiddenTrait"]' 'impl HiddenTrait for MyLibType'
impl HiddenTrait for MyLibType {}

// @!has foo/struct.T.html '//*[@id="impl-From%3CMyLibType%3E"]' 'impl From<MyLibType> for T<T<T<T<HiddenType>>>>'
impl From<MyLibType> for T<T<T<T<HiddenType>>>> {
fn from(it: MyLibType) -> T<T<T<T<HiddenType>>>> {
match it {}
}
}