Skip to content

Rustdoc generates docs for hidden methods in impls #36035

Open

Description

@Boddlnagg

I've seen #34025, but in the following case rustdoc still generates documentation for hidden() in the impl Bar for Foo (but as tymethod instead of method). It works correctly if hidden() is also marked as hidden in the trait definition.

pub struct Foo;

pub trait Bar {
    fn test();
    fn hidden();
}

impl Bar for Foo {
    fn test() {}
    #[doc(hidden)] fn hidden() {}
}

rustc -V:
rustc 1.13.0-nightly (e9bc1bac8 2016-08-24)

Activity

  1. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    on Aug 27, 2016
  2. added
    T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.
    and removed on May 18, 2017
  3. QuietMisdreavus commented on Nov 5, 2018

    @QuietMisdreavus
    Contributor

    Current status: Still a problem. Rustdoc doesn't scan the visibility of items inside a trait implementation, and in fact doesn't even check against a trait definition when printing an implementation. This leads to odd situations where if you have the #[doc(hidden)] on the definition instead, the implementation still prints the method!

    image

    This is because the pass in rustdoc that strips out private or hidden items doesn't check "tymethods" for visibility at all:

    // tymethods/macros have no control over privacy
    clean::MacroItem(..) | clean::TyMethodItem(..) => {}

    And the part that renders the final impl onto the page doesn't check visibility either.


    Looking at your sample and the code again, i think i can see what's happening:

    1. The strip-hidden pass looked at the trait definition, saw that both methods were visible, and left them in.
    2. The pass looked at the implementation, saw that one method was #[doc(hidden)], and stripped that method from that impl.
    3. The renderer looked at the impl, saw one method that was still present, and rendered it.
    4. The renderer saw that the impl had a trait on it, looked in the trait, saw a method that wasn't in the impl, and rendered that.

    That partially explains why you need #[doc(hidden)] on both for the method to be hidden, but it also confuses me after seeing that "tymethods have no control over privacy" thing. I bet #[doc(hidden)] is processed in a different place, but at least this can explain what's going on.

  4. changed the title [-]Rustdoc still generates docs for some hidden methods[/-] [+]Rustdoc generates docs for hidden methods in impls[/+] on Jul 2, 2021
  5. removed
    T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.
    on Jan 18, 2022
  6. fmease commented on Jul 27, 2022

    @fmease
    Member

    I've just stumbled upon this GitHub issue. I am actually convinced that one shouldn't be allowed to place #[doc(hidden)] on trait impl items since it doesn't really make sense to me from a conceptional / semantic point of view: When you are impl'ing a trait (and the impl block is not #[doc(hidden)] which would be absolutely fine), you promise that you fully conform to the trait's API. Why would you want to hide part of the API when people can just look up the trait's documentation and find the supposedly hidden method?

    For context, I actually went so far as to implement a lint for this (#96008, #97208) but I later had to remove it (#98336) basically because in some cases it actually does get hidden (#96890).

    Just FYI for people stopping by reading this issue.

  7. added
    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
    on Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-trait-systemArea: Trait systemC-bugCategory: This is a bug.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