-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Problem
When multiple dependencies have the same name,
running cargo rustdoc --output-format=json -p <pkg>@<ver>
sometimes won't re-run rustdoc if the version has changed.
Steps
(For a repo containing this, see https://codeberg.org/adot/cargo-rustdoc-json-bug).
We have a crate entry that depends both on dep@1.0.0 and dep@2.0.0
File: entry/Cargo.toml
[package]
name = "entry"
version = "0.1.0"
edition = "2024"
[dependencies]
dep_v1 = { path = "../dep_v1", package = "dep" }
dep_v2 = { path = "../dep_v2", package = "dep" }File: dep_v1/Cargo.toml
[package]
name = "dep"
version = "1.0.0"
edition = "2024"File: dep_v2/Cargo.toml
[package]
name = "dep"
version = "2.0.0"
edition = "2024"Then in entry/ run:
-
Make sure we're doing a clean build
$ cargo clean Removed 120 files, 637.0KiB total
-
Build rustdoc-json for
dep@1.0.0:$ cargo rustdoc --output-format=json -Zunstable-options --package=dep@1.0.0 Documenting dep v1.0.0 (/home/alona/tmp/cargo-rustdoc-json-bug/dep_v1) Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.11s Generated /home/alona/tmp/cargo-rustdoc-json-bug/entry/target/doc/dep.json
This runs
rustdoc, as expected. -
Build rustdoc-json for
dep@2.0.0:$ cargo rustdoc --output-format=json -Zunstable-options --package=dep@2.0.0 Documenting dep v2.0.0 (/home/alona/tmp/cargo-rustdoc-json-bug/dep_v2) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.56s Generated /home/alona/tmp/cargo-rustdoc-json-bug/entry/target/doc/dep.json
Even though it's outputting the same path, in re-run
rustdoc, because the package being documented has changed. -
Re-build rustdoc-json for
dep@1.0.0:$ cargo rustdoc --output-format=json -Zunstable-options --package=dep@1.0.0 Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s Generated /home/alona/tmp/cargo-rustdoc-json-bug/entry/target/doc/dep.json
For some reason this time, it doesn't re-run
rustdoc.
The filedep.jsonnow contains output fordep@2.0.0, notdep@1.0.0
Possible Solution(s)
Either cargo could somehow re-build in step 3 (as well as 2, as it currently does).
I'm not familiar enough with cargo's caching logic to say why this happens.
Alternatively we could resolve this in rustdoc, by fixing rust-lang/rust#142370.
This would involve rustdoc adding the value of -Cmetadata or -Cextra-filename.
I think this is preferable because it means that a user can switch between building dep@1.0.0 and dep@2.0.0
without having to rebuild each time, because they're not the same.
Notes
No response
Version
cargo 1.93.0-nightly (5c0343317 2025-11-18)
release: 1.93.0-nightly
commit-hash: 5c0343317ce45d2ec17ecf41eaa473a02d73e29c
commit-date: 2025-11-18
host: x86_64-unknown-linux-gnu
libgit2: 1.9.1 (sys:0.20.2 vendored)
libcurl: 8.15.0-DEV (sys:0.4.83+curl-8.15.0 vendored ssl:OpenSSL/3.5.4)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Ubuntu 25.4.0 (plucky) [64-bit]