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

cross-crate #[doc(hidden)] is ignored when listing trait implementations #86448

Closed
danielhenrymantilla opened this issue Jun 18, 2021 · 6 comments · Fixed by #86513
Closed

cross-crate #[doc(hidden)] is ignored when listing trait implementations #86448

danielhenrymantilla opened this issue Jun 18, 2021 · 6 comments · Fixed by #86513
Assignees
Labels
A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@danielhenrymantilla
Copy link
Contributor

danielhenrymantilla commented Jun 18, 2021

Context

https://users.rust-lang.org/t/hidden-trait-implementation-in-online-docs/61256/4

Repro

set -euo pipefail
cd $(mktemp -d)

cargo new -q --lib dependency
cat> dependency/src/lib.rs <<'EOF'
    #[doc(hidden)]
    pub enum HiddenType {}
    
    pub enum MyLibType {}
    impl From<HiddenType> for MyLibType {
        fn from (it: HiddenType)
          -> MyLibType
        {
            match it {}
        }
    }
EOF
(cd dependency
    set -x
    cargo doc -q --no-deps
    # No matches
    ! grep -o HiddenType target/doc/dependency/index.html
)

cargo init -q --lib --name mylib
cat> src/lib.rs <<'EOF'
    pub use ::dependency::HiddenType; // OK, not re-exported
    
    pub enum MyLibType {}
    impl From<HiddenType> for MyLibType {
        fn from (it: HiddenType)
          -> MyLibType
        {
            match it {}
        }
    }
EOF

cat>> Cargo.toml <<'EOF'
    dependency.path = 'dependency'
EOF

set -x
cargo doc -q --no-deps
# No matches
! grep -o HiddenType target/doc/mylib/index.html
# There are matches
grep -o HiddenType target/doc/mylib/enum.MyLibType.html
  • Last line yields several occurrences of HiddenType in the generated .html file.

    Expected behavior

    No occurrences of HiddenType anywhere since it was #[doc(hidden)]

  • Playground

@rustbot label C-bug T-rustdoc

cc @GuillaumeGomez

@rustbot rustbot added C-bug Category: This is a bug. T-rustdoc labels Jun 18, 2021
@jyn514
Copy link
Member

jyn514 commented Jun 21, 2021

I expect the fix is to check for doc(hidden) just after

let for_ = match &impl_item {
.

@jyn514 jyn514 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Jun 21, 2021
@fee1-dead
Copy link
Member

@rustbot claim

@fee1-dead
Copy link
Member

cc @jyn514

I checked for doc(hidden) like this:

    if let Some(did) = for_.def_id() {
        if cx.tcx.get_attrs(did).lists(sym::doc).has_word(sym::hidden) {
            return
        }
    }

But it doesn't seem to work, as my test would fail. I also tried using the same way to check for trait_ but it also failed. I noticed that the issue involves From<HiddenType> so I might need to iterate over generic parameters, I cannot find any function that does that in TyCtxt, so can someone point me in the right direction? Thanks :)

@danielhenrymantilla
Copy link
Contributor Author

You can look at how the strip-hidden-items pass works:

if let Some(generics) = imp.trait_.as_ref().and_then(|t| t.generics()) {
for typaram in generics {

@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed T-rustdoc-temp labels Jun 22, 2021
@jyn514
Copy link
Member

jyn514 commented Jun 24, 2021

@danielhenrymantilla am I right in understanding this only happens for cross-crate traits, and impls for hidden traits in the same crate are still hidden? In other words, #86513 just makes the cross-crate case consistent?

@jyn514 jyn514 added the A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate label Jun 24, 2021
@danielhenrymantilla
Copy link
Contributor Author

I believe so, yes: the strip-hidden-items pass was already taking care of such cases for local #[doc(hidden)] types. FWIW, the thing that motivated this discussion was noticing a From<Unique<T>> for ptr::NonNull<T> leaking on the docs for ::std, but not on the ones for ::core

JohnTitor added a commit to JohnTitor/rust that referenced this issue Jun 25, 2021
…=danielhenrymantilla

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

Fixes rust-lang#86448.
@bors bors closed this as completed in 6be1732 Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cross-crate-reexports Area: Documentation that has been re-exported from a different crate C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants