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

doc(hidden) stopped working in binary crates #67851

Closed
dtolnay opened this issue Jan 4, 2020 · 3 comments · Fixed by #67875
Closed

doc(hidden) stopped working in binary crates #67851

dtolnay opened this issue Jan 4, 2020 · 3 comments · Fixed by #67875
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Jan 4, 2020

rust-lang/cargo#7593 seems relevant. cc @LukasKalbertodt @Eh2406

If I have the following binary crate, cargo doc on stable 1.40.0 will correctly show g and not f, while beta will show both despite f being doc(hidden).

#[doc(hidden)]
pub fn f() {}
pub fn g() {}
fn main() {}

I understand that we want private things documented for bin crates, but I am labeling this a regression because this makes it impossible for macro-generated code to hide distracting implementation details that might overwhelm the actual useful API of the generated code.

I would like to suggest continuing to leave doc(hidden) items out of bin crate documentation as the default behavior of cargo doc.

@dtolnay dtolnay added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. labels Jan 4, 2020
@Eh2406
Copy link
Contributor

Eh2406 commented Jan 4, 2020

Your suggestion seems entirely reasonable to me. I don't know what PR wuld need to go where to impl it.

@dtolnay
Copy link
Member Author

dtolnay commented Jan 4, 2020

@rust-lang/cargo @rust-lang/rustdoc, any tips for what PRs would need to go where?

@LukasKalbertodt
Copy link
Member

Just for reference, the PR you linked (rust-lang/cargo#7593) is not directly responsible for the buggy behavior. You can see the problem with 1.40 by cargo doc --document-private-items (which also documents f).

Could it be that we simply have to add a STRIP_HIDDEN pass here (and potentially some other arrays in that file)?

pub const DEFAULT_PRIVATE_PASSES: &[Pass] = &[
COLLECT_TRAIT_IMPLS,
COLLAPSE_DOCS,
UNINDENT_COMMENTS,
CHECK_PRIVATE_ITEMS_DOC_TESTS,
STRIP_PRIV_IMPORTS,
COLLECT_INTRA_DOC_LINKS,
CHECK_CODE_BLOCK_SYNTAX,
PROPAGATE_DOC_CFG,
];

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jan 6, 2020
Distinguish between private items and hidden items in rustdoc

I believe rustdoc should not be conflating private items (visibility lower than `pub`) and hidden items (attribute `doc(hidden)`). This matters now that Cargo is passing --document-private-items by default for bin crates. In bin crates that rely on macros, intentionally hidden implementation details of the macros can overwhelm the actual useful internal API that one would want to document.

This PR restores the strip-hidden pass when documenting private items, and introduces a separate unstable --document-hidden-items option to skip the strip-hidden pass. The two options are orthogonal to one another.

Fixes rust-lang#67851. Closes rust-lang#60884.
Centril added a commit to Centril/rust that referenced this issue Jan 7, 2020
Distinguish between private items and hidden items in rustdoc

I believe rustdoc should not be conflating private items (visibility lower than `pub`) and hidden items (attribute `doc(hidden)`). This matters now that Cargo is passing --document-private-items by default for bin crates. In bin crates that rely on macros, intentionally hidden implementation details of the macros can overwhelm the actual useful internal API that one would want to document.

This PR restores the strip-hidden pass when documenting private items, and introduces a separate unstable --document-hidden-items option to skip the strip-hidden pass. The two options are orthogonal to one another.

Fixes rust-lang#67851. Closes rust-lang#60884.
@bors bors closed this as completed in 03fe834 Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-cargo Relevant to the cargo team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants