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 generates docs for hidden methods in impls #36035

Open
Boddlnagg opened this issue Aug 27, 2016 · 2 comments
Open

Rustdoc generates docs for hidden methods in impls #36035

Boddlnagg opened this issue Aug 27, 2016 · 2 comments
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-trait-system Area: Trait system C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Boddlnagg
Copy link
Contributor

Boddlnagg commented Aug 27, 2016

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)

@steveklabnik steveklabnik added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Aug 27, 2016
@steveklabnik steveklabnik added T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. and removed T-tools labels May 18, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
@QuietMisdreavus
Copy link
Member

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.

@jyn514 jyn514 changed the title Rustdoc still generates docs for some hidden methods Rustdoc generates docs for hidden methods in impls Jul 2, 2021
@ehuss ehuss removed the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label Jan 18, 2022
@fmease
Copy link
Member

fmease commented Jul 27, 2022

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.

@lolbinarycat lolbinarycat added A-trait-system Area: Trait system A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. labels Nov 8, 2024
@fmease fmease added A-trait-system Area: Trait system and removed A-trait-system Area: Trait system labels Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-trait-system Area: Trait system C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants