Skip to content
Latchkey

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

Common 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

FlagEffect
--no-depsDo not document dependencies
--openOpen the docs after building
--workspaceDocument all members
--document-private-itemsInclude private items

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →