No description
Find a file
2025-11-22 18:16:39 +00:00
dep_v1 writeup issue 2025-11-22 18:16:39 +00:00
dep_v2 writeup issue 2025-11-22 18:16:39 +00:00
entry mcve 2025-11-22 17:57:33 +00:00
README.md writeup issue 2025-11-22 18:16:39 +00:00

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:

  1. Make sure we're doing a clean build

    $ cargo clean
     Removed 120 files, 637.0KiB total
    
  2. 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.

  3. 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.

  4. 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 file dep.json now contains output for dep@2.0.0, not dep@1.0.0

Possible Solution

Either cargo could somehow re-build in step 3 (as well as 2, as it currently does). I'm not framiliar enough with cargo's cacheing logic to say why this happens.

Alternativly we could resolve this in rustdoc, by fixing https://github.com/rust-lang/rust/issues/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.

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]