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: #[doc(hidden)] should not apply recursively #81980

Closed
jyn514 opened this issue Feb 11, 2021 · 5 comments
Closed

Rustdoc: #[doc(hidden)] should not apply recursively #81980

jyn514 opened this issue Feb 11, 2021 · 5 comments
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Feb 11, 2021

I tried this code:

#[doc(hidden)]
pub mod inner {
  pub struct S;
}
pub use inner::S;

I expected to see this happen: Rustdoc generates docs for S but not inner, since the pub use does not have a doc(hidden) attribute.

Instead, this happened: Rustdoc doesn't generate docs for either (presumably because it applies doc(hidden) recursively).

Additionally, I tried this code:

#[doc(hidden)]
pub use context_api;
mod context_api;

but got a name resolution error:

error[E0255]: the name `context_api` is defined multiple times
   --> src/lib.rs:155:1
    |
153 | pub use context_api;
    |         ----------- previous import of the module `context_api` here
154 | 
155 | mod context_api;
    | ^^^^^^^^^^^^^^^^ `context_api` redefined here
    |
    = note: `context_api` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
    |
153 | pub use context_api as other_context_api;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0365]: `context_api` is private, and cannot be re-exported
   --> src/lib.rs:153:9
    |
153 | pub use context_api;
    |         ^^^^^^^^^^^ re-export of private `context_api`
    |
    = note: consider declaring type or module `context_api` with `pub`

Both of those combined means there's no way to display the docs for only the module and not its items.

Meta

rustdoc --version: rustdoc 1.52.0-nightly (9778068 2021-02-07)

@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Feb 11, 2021
@jyn514
Copy link
Member Author

jyn514 commented Feb 11, 2021

Additionally, publicly re-exporting it under a different name doesn't work:

error[E0365]: `context_api_` is private, and cannot be re-exported
   --> src/lib.rs:152:9
    |
152 | pub use context_api_ as context_api;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^ re-export of private `context_api_`
    |
    = note: consider declaring type or module `context_api_` with `pub`

@jyn514
Copy link
Member Author

jyn514 commented Feb 11, 2021

Ok, as a workaround I can mark other imports as doc(inline) and that works correctly.

#[doc(hidden)]
mod context_api;
#[doc(inline)]
pub use context_api::*;

I think rustdoc should inline these automatically if the original module has doc(hidden).

@jyn514
Copy link
Member Author

jyn514 commented Feb 11, 2021

For clarification, my use case for this is that context_api was public in the last release, and making it private would introduce unnecessary churn. Using doc(hidden) is like a 'soft deprecation' without adding a bunch of warnings.

@jyn514 jyn514 changed the title Rustdoc: There is no way to hide only a module and not its items Rustdoc: #[doc(hidden)] should not apply recursively Feb 11, 2021
@Nemo157
Copy link
Member

Nemo157 commented May 20, 2021

Also see #59368 which has mentions of this issue.

@jyn514
Copy link
Member Author

jyn514 commented May 21, 2021

Oh good point, I think this is a duplicate.

@jyn514 jyn514 closed this as completed May 21, 2021
nars1 pushed a commit to YottaDB/YDBRust that referenced this issue Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

3 participants