Skip to content

Only document reachable APIs with cargo doc#16603

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

Only document reachable APIs with cargo doc#16603
ojuschugh1 wants to merge 2 commits intorust-lang:masterfrom
ojuschugh1:fix-doc-direct-deps-2025

Conversation

@ojuschugh1
Copy link
Contributor

@ojuschugh1 ojuschugh1 commented Feb 8, 2026

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
Copy link
Collaborator

rustbot commented Feb 8, 2026

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

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
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
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
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
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

@ojuschugh1
Copy link
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
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
Copy link
Contributor

Choose a reason for hiding this comment

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

No test updates are in this commit. Either the tests in the previous commit are failing or there is a mismatch in expectations between the tests and this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was marked as ready for review but this doesn't seem to be addressed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any questions about this has there have been more commits pushed without addressing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies for the confusion! I did address the feedback:

  1. Simplified the boolean expression from .require().is_ok() to .is_enabled() as you suggested
  2. Verified all tests pass including the public-dependency tests

I should have been clearer in my commit messages about which feedback was being addressed. The code changes are now in place and working correctly. Is there anything specific you'd like me to clarify or improve further?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unsure if this has been said in this thread before but we find it helpful for authors, reviewers, and the community when a PR has the tests added in their own commit before the fix with them passing, reproducing the existing behavior. The commit with the fix would then update the tests to still pass and show the new behavior. The diff would show how behavior changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in latest commit, just curious to confirm we do this before fix test + fix and updated test commit method for all the code changes PRs ?

Thanks

@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
Copy link
Contributor Author

ojuschugh1 commented Mar 8, 2026

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
@ojuschugh1 ojuschugh1 force-pushed the fix-doc-direct-deps-2025 branch from 5d84a47 to 07b6c1b Compare March 10, 2026 16:52
Comment on lines +677 to +678
let should_doc_dep = if is_member || !public_deps_enabled {
true
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be is_member or is_root?

If I have

  • workspace members selected and skipped
  • selected has a private dependency on skipped
  • I run cargo doc -p selected

Should we document the dependencies of skipped?

Either way, we should have a test for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a hole in that example. We document dependencies by default, so the private status of skipped is irrelevant. Some layers might be needed to make the use case correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test doc_workspace_member_private_dep for this. Using is_member - workspace members get their deps documented regardless of how another member depends on them.

Copy link
Contributor

Choose a reason for hiding this comment

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

But is that the behavior we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have renamed is_root to is_user_selected (backed by root_pkg_ids in State), which more precisely captures the intent: these are packages explicitly selected by the user (e.g. via -p), not just workspace members. The filter now only applies to deps of non-user-selected packages.

}

#[cargo_test(nightly, reason = "public-dependency feature is unstable")]
fn doc_with_private_dependency() {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should call out that this is a transitive private dependency

@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
}

#[cargo_test(nightly, reason = "public-dependency feature is unstable")]
fn doc_workspace_member_private_dep() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test was added in the wrong commit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks

Comment on lines +4035 to +4039
// foo is the selected package
// bar is a direct dep of foo
// baz is a public dep of bar
// qux is a public dep of baz

Copy link
Contributor

Choose a reason for hiding this comment

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

better than comments like this is to name the packages for their role in the test, e.g.

  • foo -> selected
  • bar -> foo-dep
  • baz -> public-bar-dep
  • qux -> public-baz-dep

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed, thanks

@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
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