Skip to content
Latchkey

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

Terminal
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 --open

Options

Flag / envWhat it does
--no-depsDocument only this crate, not dependencies
--openOpen the generated docs in a browser
--all-featuresEnable every feature while documenting
--document-private-itemsInclude private items in the docs
--workspaceDocument 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`.

Related guides

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