I just created a new Rust project and introduced one dependency in main.rs
. When I try to run rustdoc src/main.rs
, I get the following error:
error[E0433]: failed to resolve: maybe a missing crate `rand`?
--> src/main.rs:4:5
Even though Cargo.toml
has that dependency already, it's installed and in Cargo.lock
, it's imported in main.rs
through use rand;
and the project builds successfully, without any issues.
[package]
name = "test"
version = "0.1.0"
edition = "2021"
[dependencies]
rand = "0.8.5"
I saw some answers point to edition being absent or set to earlier versions as the cause; this is not the case here. I tried creating documents for fresh libraries or binaries as described in the documentation, but it works until I introduce a dependency, when the same error repeats.
Project structure (the rustdoc
command is run from root):
├── Cargo.lock
├── Cargo.toml
├── readme.md
└── src
└── main.rs
Any help is appreciated!
To summarize the solution,
cargo
has an integration withrustdoc
which solves the dependency problem automatically - the example given in the basic usage documentation only works when there are no dependencies. Just runningcargo doc
in the root will generate the wanted documentation, however under thetarget/doc
path.Thanks for the help!