Open
Description
Problem
I want to use cargo rustdoc
to document code in my unit and integration test modules. Following command does the trick and generates the documentation I desire:
$ RUSTDOCFLAGS="--document-private-items --cfg test" cargo rustdoc --tests
BUT the command fails if I am using dev-dependencies in the unit tests, which I need to. It does not fail when using dev-dependencies in integration tests.
The reason for the failure is that the dev-dependencies do not get linked via --extern
for unit tests, but they do get linked for integration tests.
Steps
$ git clone https://github.com/Urhengulas/cargo-rustdoc-error-report-example
$ cd cargo-rustdoc-error-report-example/
$ RUSTDOCFLAGS="--document-private-items --cfg test" cargo rustdoc --tests
error[E0432]: unresolved import `rand`
--> src/lib.rs:3:9
|
3 | use rand::random;
| ^^^^ use of undeclared crate or module `rand`
The use of the rand
crate is random (🥁), it fails with any dev-dependency.
Possible Solution(s)
Linking dev-dependencies when documenting unit test would solve the problem for me.
Notes
No response
Version
cargo 1.80.1 (376290515 2024-07-16)
release: 1.80.1
commit-hash: 37629051518c3df9ac2c1744589362a02ecafa99
commit-date: 2024-07-16
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Fedora 40.0.0 [64-bit]