Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Difference between `cargo doc` and `cargo rustdoc`

According to doc.rust-lang.org

build[s] a package’s documentation, using specified custom flags

build[s] a package’s documentation

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is the difference between the two? From what I understand cargo rustdoc is just like cargo doc, but it allows for more lints—for instance:

#![deny(rustdoc::broken_intra_doc_links)]

Is this correct? Oddly enough, cargo rustdoc will also fail in certain situations where cargo doc doesn’t. For instance

some/folder on some-branch [$!] via 🦀 v1.60.0-nightly
❯ cargo doc
    Finished dev [unoptimized + debuginfo] target(s) in 0.53s

some/folder on some-branch [$!] via 🦀 v1.60.0-nightly
❯ cargo rustdoc
error: manifest path `some/folder/Cargo.toml` is a virtual manifest, but this command requires running against an actual package in this workspace

Also, cargo doc does not support adding the -D option, whereas cargo rustdoc does.

❯ cargo doc -- -D rustdoc::broken_intra_doc_links
error: Found argument '-D' which wasn't expected, or isn't valid in this context

USAGE:
    cargo doc [OPTIONS]

For more information try --help

>Solution :

Their relationship is like between cargo build and cargo rustc: cargo doc performs the usual work, for an entire workspace, including dependencies (by default). cargo rustdoc allows you to pass flags directly to rustdoc, and only works for a single crate.

Here is the execution code for cargo rustdoc. Here is the code for cargo doc. The only differences is that cargo rustdoc always specify to not check dependencies while cargo doc allows you to check (by default it does, but you can specify the flag --no-deps), and that cargo rustc allows you to pass flags directly to rustdoc with the --args flag.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading