Skip to content

Only document reachable APIs with cargo doc - #16603

Open
ojuschugh1 wants to merge 2 commits into
rust-lang:masterfrom
ojuschugh1:fix-doc-direct-deps-2025
Open

ojuschugh1 wants to merge 2 commits into
rust-lang:masterfrom
ojuschugh1:fix-doc-direct-deps-2025

Conversation

@ojuschugh1

@ojuschugh1 ojuschugh1 commented Feb 8, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

What does this PR try to resolve?

Fixes #2025

Adds support for documenting only direct dependencies when using the public-dependency feature. Currently cargo doc generates docs for all transitive dependencies, which creates a lot of noise. With this change, when -Zpublic-dependency is enabled, only direct deps and their public deps get documented.

Backward compatible - without the flag everything works as before.

@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch from 12fa44b to e7d5853 Compare February 8, 2026 17:50
@ojuschugh1
ojuschugh1 marked this pull request as ready for review February 8, 2026 17:51
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 8, 2026
@rustbot

rustbot commented Feb 8, 2026

Copy link
Copy Markdown
Collaborator

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

Comment thread tests/testsuite/doc_direct_deps.rs Outdated
Comment thread tests/testsuite/doc_direct_deps.rs Outdated
Comment thread tests/testsuite/doc_direct_deps.rs Outdated
Comment thread tests/testsuite/doc_direct_deps.rs Outdated
pub_dep = { version = "0.0.1", public = true }
priv_dep = { version = "0.0.1", public = false }
priv_dep_with_dep = "0.0.1"
"#,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is checking the mixed case for direct deps and not transitive deps. Is that intentional or did you meant for these to be indirect?

And what is it we are trying to get out of the mixed test vs other tests added?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what is it we are trying to get out of the mixed test vs other tests added?

Could you help me understand the role of this test?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ojuschugh1 there are outstanding questions on this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ojuschugh1 this is still unaddressed while other work continues

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing this again. It was meant to cover public, private and unannotated deps in one manifest, but the direct part is already covered by doc_direct_deps_always_documented and the transitive part by doc_with_transitive_private_dependency, so it wasn't adding anything. I've dropped it.

Comment thread tests/testsuite/doc_direct_deps.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently cargo doc generates docs for all transitive dependencies, which creates a lot of noise.

This allows library authors to control their documentation surface by
marking which dependencies are part of their public API.

The reason is that indirect private deps have no impact on the reader of the docs since they cannot be used and this can dramatically speed up documentation builds, especially with packages like windows-sys in a dependency tree

Comment thread src/compiler/unit_dependencies.rs
Comment thread src/cargo/core/compiler/unit_dependencies.rs Outdated
Comment thread tests/testsuite/doc_direct_deps.rs Outdated
Comment thread tests/testsuite/doc_direct_deps.rs Outdated
@ojuschugh1

Copy link
Copy Markdown
Contributor Author

I have addressed your comments and feedback, kindly please review it and let me know @epage , after that i will make the commits proper.

thanks

@ranger-ross

Copy link
Copy Markdown
Member

@ojuschugh1 Would you mind cleaning up the commits to be atomic? (mentioned in the contributor guide)

Atomic commits aren't just for Git history, they make it easier for reviewers to review changes.

@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch from 2fd32b8 to d0ffd36 Compare February 10, 2026 17:33
@ojuschugh1
ojuschugh1 requested a review from epage February 11, 2026 14:49
Comment thread src/compiler/unit_dependencies.rs
Comment thread tests/testsuite/doc.rs
Comment thread tests/testsuite/doc.rs Outdated
@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch from d0ffd36 to a6cc3a8 Compare February 11, 2026 18:26
@ojuschugh1
ojuschugh1 requested a review from epage February 11, 2026 18:43
@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch 3 times, most recently from a48ae5c to 31b786c Compare February 12, 2026 18:11
@ojuschugh1
ojuschugh1 marked this pull request as draft February 12, 2026 18:12
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 12, 2026
@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch from 31b786c to d327857 Compare February 12, 2026 18:42
@ojuschugh1
ojuschugh1 marked this pull request as ready for review February 14, 2026 09:15
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 14, 2026
@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch from d327857 to 7e57124 Compare February 14, 2026 09:39
@ojuschugh1

ojuschugh1 commented Mar 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @epage , Gentle reminder could you kindly please reivew it, when you get a moment.

Thanks

@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch from 7e57124 to 5d84a47 Compare March 10, 2026 15:48
Comment thread tests/testsuite/doc.rs Outdated
Comment thread src/cargo/core/compiler/unit_dependencies.rs Outdated
Comment thread src/cargo/core/compiler/unit_dependencies.rs Outdated
@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch from 5d84a47 to 07b6c1b Compare March 10, 2026 16:52
Comment thread tests/testsuite/doc.rs Outdated
Comment thread src/cargo/core/compiler/unit_dependencies.rs Outdated
Comment thread tests/testsuite/doc.rs Outdated
Comment thread tests/testsuite/doc.rs Outdated
@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch 2 times, most recently from fe28062 to 6e9b1f3 Compare March 10, 2026 18:39
Comment thread tests/testsuite/doc.rs
Comment thread tests/testsuite/doc.rs Outdated
@epage epage changed the title Fix doc direct deps 2025 Only document reachable APIs with cargo doc Mar 11, 2026
@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch from 6e9b1f3 to 9ccbd9a Compare March 14, 2026 18:59
@ojuschugh1
ojuschugh1 requested a review from epage March 14, 2026 19:06
@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch from 9ccbd9a to 7c20eb2 Compare March 22, 2026 16:59
Comment thread tests/testsuite/doc.rs Outdated
@rustbot

This comment has been minimized.

@ojuschugh1
ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch from 7c20eb2 to 2df9612 Compare September 27, 2026 06:00
@rustbot

rustbot commented Sep 27, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@ojuschugh1
ojuschugh1 requested a review from epage September 27, 2026 06:06
@ojuschugh1

Copy link
Copy Markdown
Contributor Author

Hey @epage hope you are doing well. It has been a while since this PR so i thought to fix the remaining comments so that it can closed, could you kindly look into this when you get a moment.

Thanks !

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo doc only direct dependencies

5 participants