How can I include private modules when generating documentation via Cargo?

Use cargo to document private items:

cargo doc --document-private-items

This can be done by passing arguments to rustdoc, after --, eg.

cargo rustdoc -- \
    --no-defaults \
    --passes strip-hidden \
    --passes collapse-docs \
    --passes unindent-comments \
    --passes strip-priv-imports

Based on @Shepmaster's answer, no need for manual copy-pasting.


This is now simpler, just use:

cargo rustdoc -- --document-private-items

Rust 1.41

Documentation for binaries includes private items from the binary crate by default.

Rust 1.29

You can now use cargo doc --document-private-items

Previous versions

You may not be able to do it with Cargo today, there is a workaround if you use rustdoc directly.

Run cargo doc -v and make a note of the rustdoc command it runs:

$ cargo doc -v
   Compiling docz v0.0.1 (file:///private/tmp/docz)
     Running `rustdoc src/lib.rs -o /private/tmp/docz/target/doc --crate-name docz -L dependency=/private/tmp/docz/target/debug -L dependency=/private/tmp/docz/target/debug/deps`

Then, add --no-defaults --passes strip-hidden --passes collapse-docs --passes unindent-comments to the command:

rustdoc src/lib.rs -o /private/tmp/docz/target/doc --crate-name docz \
    -L dependency=/private/tmp/docz/target/debug \
    -L dependency=/private/tmp/docz/target/debug/deps \
    --no-defaults \
    --passes strip-hidden --passes collapse-docs --passes unindent-comments