Skip to content

rustdoc: #[doc(hidden)] associated items of traits re-exported from external crates are not hidden in certain impl blocks  #95717

Closed
@fmease

Description

@fmease

Minimal reproducible example (on stable and nightly):

// in crate `alpha`

pub trait Tr {
    #[doc(hidden)]
    type Assoc;
}

pub struct Ty;

impl Tr for Ty {
    type Assoc = ();
}
// in crate `beta` (which depends on `alpha`)

pub use alpha::{Tr, Ty};    // glob would also work

Document crate beta and take a look at the generated pages of Tr and Ty:
You should be able to actually see the associated type Assoc in the impl block despite being marked as hidden. You probably need to click [+] (expand) first.
The impl block I refer to is in section

  • Implementors on the trait page and in section
  • Trait Implementations on the implementor's page.

It should be noted that even though Assoc wrongly shows up in those impl blocks, it is indeed not shown in the code block at the start of the trait page – at the “definition site” if you will (compared to the “use sites” – the impl blocks).

It is crucial that the trait and the type are defined inside of an external crate. If they were defined in the “current” crate, this bug would not occur: The hidden associated items would not be shown.
You can check this for yourself by

  • documenting alpha on its own and viewing its documentation separately, or by
  • re-exporting the crate alpha from beta (e.g. with pub use alpha;) and then documenting beta:
    • On the page for alpha::Tr, the associated item is hidden
    • On the page for the re-export beta::Tr, however, the associated item is displayed

I've discovered this bug in a PR of mine after a CI job failed because the linkchecker complained about broken links in the standard library when documenting it with a modified rustdoc. The broken links are not relevant for this bug, they are mere symptoms of it: If everything was properly hidden, no broken links would ever be generated.

This bug currently affects the standard library documentation (for stable and nightly) as mentioned in the linked comment.
In this case,

  • the trait is SupportedLaneCount
  • the type is LaneCount
  • the associated type that shouldn't be shown is BitMask
  • crate “alpha” is core
  • crate “beta” is std

@rustbot label T-rustdoc A-cross-crate-reexports

Metadata

Metadata

Assignees

Labels

A-cross-crate-reexportsArea: Documentation that has been re-exported from a different crateC-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