cargo doc --no-deps: Build Docs in CI
cargo doc --no-deps generates HTML documentation for the workspace crates without also documenting every dependency.
Documenting dependencies is slow and rarely what you publish. --no-deps keeps the build fast, and RUSTDOCFLAGS lets you fail on broken intra-doc links.
What it does
cargo doc runs rustdoc to produce HTML under target/doc. --no-deps documents only the local packages, skipping dependencies. Setting RUSTDOCFLAGS="-D warnings" turns rustdoc lints (like broken intra-doc links) into hard errors.
Common usage
cargo doc --no-deps --all-features --locked
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps
cargo doc --no-deps --document-private-itemsFlags
| Flag | What it does |
|---|---|
| --no-deps | Do not build documentation for dependencies |
| --all-features | Document with all features enabled |
| --document-private-items | Include private items in the docs |
| --open | Open the docs in a browser (local only, not CI) |
| RUSTDOCFLAGS=-D warnings | Env var: fail on rustdoc warnings |
In CI
Use RUSTDOCFLAGS="-D warnings" to catch broken doc links before they ship. Cache ~/.cargo and target/ so doc builds reuse compiled dependency metadata. Do not use --open in CI; there is no browser.
Common errors in CI
"error: unresolved link to Foo" with -D warnings means an intra-doc link points at something that does not exist or is not imported in scope. "error: [...] cannot be resolved" is the same class. Without the deny flag these are warnings and the docs still build, so the gate only triggers when RUSTDOCFLAGS is set.