cargo doc: Usage, Options & Common CI Errors
Generate HTML API docs from your source and doc comments.
cargo doc runs rustdoc to build documentation for your package and its dependencies, writing HTML to target/doc. It is commonly wired into CI to catch broken intra-doc links.
What it does
Compiles doc comments and item signatures into a browsable HTML site. By default it documents dependencies too; --no-deps limits output to your own crate.
Common usage
Terminal
cargo doc # build docs (incl. deps)
cargo doc --no-deps # only this crate
cargo doc --open # build and open in a browser
RUSTDOCFLAGS="-D warnings" cargo doc --no-depsCommon CI error: broken intra-doc links
A doc-link gate fails because a [Type] reference no longer resolves. rustdoc emits "warning: unresolved link to ...", and with RUSTDOCFLAGS="-D warnings" that becomes an error. Fix: correct the path in the doc comment, or import the item so the link resolves.
Options
| Flag | Effect |
|---|---|
| --no-deps | Do not document dependencies |
| --open | Open the docs after building |
| --workspace | Document all members |
| --document-private-items | Include private items |
Related guides
cargo check: Usage, Options & Common CI Errorscargo check type-checks your crate without producing a binary, making it the fast CI gate. See usage, --works…
cargo publish: Usage, Options & Common CI Errorscargo publish uploads a crate to crates.io. Learn --dry-run, --token for CI, and how to fix "already uploaded…
go doc: Usage, Options & Common CI Errorsgo doc prints documentation for a package, symbol, or method from the command line. Learn -all and -src, and…