Skip to content

Rustdoc is showing definitions of "private" types in type def documentation #142019

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

Open
weiznich opened this issue Jun 4, 2025 · 3 comments
Open
Labels
A-local-reexports Area: Documentation that has been locally re-exported (i.e., non-cross-crate) A-visibility Area: Visibility / privacy C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@weiznich
Copy link
Contributor

weiznich commented Jun 4, 2025

I tried this code:

diesel-rs/diesel@116e868

cargo +nightly doc --open -p diesel --no-deps

Search for diesel::dsl::Eq afterwards to get to this page

I expected to see this happen: Rustdoc hides the aliased type + tuple field sections as the Grouped by type is not exposed as part of the public API. (That type is in a crate local module)

Instead, this happened: Rustdoc shows information about private types.

Meta

rustdoc --version --verbose:

rustdoc 1.89.0-nightly (59aa1e873 2025-06-03)
binary: rustdoc
commit-hash: 59aa1e873028948faaf8b97e5e02d4db340ad7b1
commit-date: 2025-06-03
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

@weiznich weiznich added the C-bug Category: This is a bug. label Jun 4, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 4, 2025
@weiznich weiznich changed the title Rustdoc is showing definitions of types marked as #[doc(hidden)] in type def documentation Rustdoc is showing definitions of "private" types in type def documentation Jun 4, 2025
@rustbot rustbot added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jun 4, 2025
@fmease fmease added A-visibility Area: Visibility / privacy A-local-reexports Area: Documentation that has been locally re-exported (i.e., non-cross-crate) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 4, 2025
@bjorn3
Copy link
Member

bjorn3 commented Jun 4, 2025

Does it work correctly if you mark the field as pub(crate)? The Grouped type is a public part of the api, even if the user can't directly reference the type. It seems like you can do my_eq.0.0 to access the field of the Grouped type if my_eq is an instance of the public diesel::dsl::Eq type.

@aDotInTheVoid aDotInTheVoid added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Jun 4, 2025
weiznich added a commit to weiznich/diesel that referenced this issue Jun 6, 2025
It seems like rustdoc has become to clever. See
rust-lang/rust#142019 for details.
@weiznich
Copy link
Contributor Author

weiznich commented Jun 6, 2025

I added a #[doc(hidden)] attribute to the Grouped struct and now the output looks somewhat better. That results in the following output:

Image

This is still not perfect as it now seems to claim that type Eq = Grouped<> is just an alias to the type struct Eq which is rather wrong. (It's an alias to Grouped).

You are correct that you could access the inner fields of that type. For diesel we just decided at some point that only what's visible in the documentation is considered to be part of the public API, anything else is: Use it at your own risk.

@weiznich
Copy link
Contributor Author

weiznich commented Jun 6, 2025

The following code placed in a new crate in a lib.rs file reproduces the problem:

mod my_eq {
    #[doc(hidden)]
    pub struct Eq<L, R> {
        l: L,
        r: R,
    }
}

mod my_grouped {
    pub struct Grouped<I>(pub I);
}

pub type Eq<L, R> = self::my_grouped::Grouped<self::my_eq::Eq<L, R>>;

github-merge-queue bot pushed a commit to diesel-rs/diesel that referenced this issue Jun 6, 2025
It seems like rustdoc has become to clever. See
rust-lang/rust#142019 for details.
weiznich added a commit to weiznich/diesel that referenced this issue Jun 6, 2025
It seems like rustdoc has become to clever. See
rust-lang/rust#142019 for details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-local-reexports Area: Documentation that has been locally re-exported (i.e., non-cross-crate) A-visibility Area: Visibility / privacy C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example 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

5 participants