Skip to content

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

Closed

Description

@danielhenrymantilla

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

Activity

  1. jyn514 commented on Jun 21, 2021

    @jyn514
    Member

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

    let for_ = match &impl_item {
    .

  2. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    on Jun 21, 2021
  3. fee1-dead commented on Jun 21, 2021

    @fee1-dead
    Member

    @rustbot claim

  4. fee1-dead commented on Jun 21, 2021

    @fee1-dead
    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 :)

  5. danielhenrymantilla commented on Jun 21, 2021

    @danielhenrymantilla
    ContributorAuthor

    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 {

  6. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    and removed on Jun 22, 2021
  7. jyn514 commented on Jun 24, 2021

    @jyn514
    Member

    @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?

  8. added
    A-cross-crate-reexportsArea: Documentation that has been re-exported from a different crate
    on Jun 24, 2021
  9. danielhenrymantilla commented on Jun 24, 2021

    @danielhenrymantilla
    ContributorAuthor

    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

  10. added 2 commits that reference this issue on Jun 25, 2021
    8875e72
    6be1732
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-cross-crate-reexportsArea: Documentation that has been re-exported from a different crateC-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions