@@ -637,6 +637,17 @@ fn compute_deps_doc(
637637 // built. If we're documenting *all* libraries, then we also depend on
638638 // the documentation of the library being built.
639639 let mut ret = Vec :: new ( ) ;
640+ let is_root = state. ws . is_member ( & unit. pkg ) ;
641+
642+ // Check if public-dependency feature is enabled
643+ let public_deps_enabled = state. gctx . cli_unstable ( ) . public_dependency
644+ || unit
645+ . pkg
646+ . manifest ( )
647+ . unstable_features ( )
648+ . require ( Feature :: public_dependency ( ) )
649+ . is_ok ( ) ;
650+
640651 for ( id, deps) in state. deps ( unit, unit_for) {
641652 let Some ( dep_lib) = calc_artifact_deps ( unit, unit_for, id, & deps, state, & mut ret) ? else {
642653 continue ;
@@ -657,7 +668,20 @@ fn compute_deps_doc(
657668 IS_NO_ARTIFACT_DEP ,
658669 ) ?;
659670 ret. push ( lib_unit_dep) ;
660- if dep_lib. documented ( ) && state. intent . wants_deps_docs ( ) {
671+
672+ // Decide whether to document this dependency.
673+ // When public-dependency is enabled, only document:
674+ // - Direct dependencies of workspace members
675+ // - Public dependencies (recursively)
676+ // This dramatically speeds up documentation builds by excluding indirect
677+ // private dependencies that cannot be used by readers of the docs.
678+ let should_doc_dep = if public_deps_enabled {
679+ is_root || state. resolve ( ) . is_public_dep ( unit. pkg . package_id ( ) , id)
680+ } else {
681+ true
682+ } ;
683+
684+ if dep_lib. documented ( ) && state. intent . wants_deps_docs ( ) && should_doc_dep {
661685 // Document this lib as well.
662686 let doc_unit_dep = new_unit_dep (
663687 state,
0 commit comments