cargo doc --no-deps: Build Rust API Docs
cargo doc --no-deps invokes rustdoc to generate HTML documentation for your crate only, skipping dependencies.
cargo doc is the Rust doc builder. --no-deps keeps the output focused on your crate; in CI, setting RUSTDOCFLAGS=-Dwarnings turns broken doc links into hard failures.
What it does
cargo doc compiles the crate with rustdoc, extracting /// and //! doc comments and running doc tests when asked. --no-deps documents only the current crate, not every dependency. Output lands in target/doc.
Common usage
cargo doc --no-deps
# fail on any rustdoc warning (broken links, etc.)
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps
# open the result locally
cargo doc --no-deps --openOptions
| Flag / env | What it does |
|---|---|
| --no-deps | Document only this crate, not dependencies |
| --open | Open the generated docs in a browser |
| --all-features | Enable every feature while documenting |
| --document-private-items | Include private items in the docs |
| --workspace | Document every crate in the workspace |
| RUSTDOCFLAGS="-D warnings" | Env: promote rustdoc warnings to errors |
In CI
Set RUSTDOCFLAGS="-D warnings" so a broken intra-doc link fails the build, and pass --all-features if your public API is feature-gated. Cache the target/ directory keyed on Cargo.lock. To publish to Pages, copy target/doc and add an index redirect to your crate.
Common errors in CI
error: unresolved link to SomeType` (the rustdoc::broken_intra_doc_links lint) is the most common failure under -D warnings; fix or fully-qualify the link. error: [...] public documentation for x links to private item comes from rustdoc::private_intra_doc_links. error: unknown start of token in a doc test means a code fence needs to be marked text or ignore`.