-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cargo doc
doesn't document dependencies that are using the semver trick
#10241
Comments
Thanks for the detailed writeup! Your analysis is spot on. I didn't consider this situation with the orphan check. I've been trying to think of an easy way to address this, but everything I think of is either risky or complicated. I'm wondering if it would be better to just try to do the proper fix. rustdoc needs a way for cargo to tell it where each crate is located. Then cargo could come up with some directory naming scheme to allow duplicates. I don't think it should be too difficult. However, some thought needs to be put in if |
Yeah, I was afraid of that, but I think you're right, and doing that provides other benefits as well :) |
As a newbie going through the book, I found the "work-around" from #10723 useful: |
@carols10cents @xapimaze thank you for the details. Can someone provide a summary for those like myself introducing themselves to rust through the book, who experienced the error, and are curious what the issue is here? Is it related to the fact that And the Much appreciated! |
Triage: I think we're waiting for a way to communicate with rustdoc. See #10241 (comment). @rustbot label +S-blocked-external |
Problem
If a crate
foo
depends on a crate (say, an older version ofrand
) that uses the semver trick where an older version ofrand
depends on a newer version ofrand
such that the crate is an ancestor of an older version of itself in the dependency tree, then runningcargo doc
forfoo
will not include any docs for any version ofrand
.What happens
rand
doesn't appear in the "Crates" sidebar of foo's documentation,rustdoc
invocation lines foreither version in
cargo
's verbose outputWhat I expected to happen
I expected
rand
to be in the sidebar and link to documentation similar towhat appears on https://docs.rs/rand/0.3.23/rand/index.html
Steps
Check out this repo, or perform these steps:
The dependency tree is now:
Then run:
and look at the sidebar in the generated docs; no
rand
will be present. Lookat the verbose
cargo
output; norustdoc
invocation forrand
will bepresent.
Possible Solution(s)
I believe this was introduced in:
cargo doc
and the new feature resolver. #9077and it's a combination of removing older/smaller versions in favor of newer/larger versions (so rand 0.3.22 gets removed in favor of rand 0.4.0), which was added in the first PR, and then pruning orphaned units (rand 0.4.0 is orphaned because it was only a child of rand 0.3.22, which was removed), which was added in the second PR.
I tried working on a solution but I'm not sure the best way to fix it. I'm going to open a PR for the failing test I have at least.
Notes
Variations that don't reproduce the problem
rand
repo commit 577d2a0 (there's no tag for0.3.23) and run
cargo doc
successfully. I do see the "output filenamecollision" warning and both versions being documented in
cargo
's verboseoutput. I do see
rand
0.3.23 documented as expected because 0.3.23 appearsto be consistently last and win the collision.
rand
locally, then in thefoo
crate adda
path
dependency instead of a registry dependency, I see the "outputfilename collision" warning. I do see
rand
in the sidebar and I seeboth versions being documented in
cargo
's verbose output. I do seerand
0.3.23 documented as expected because 0.3.23 appears to be consistently last
and win the collision.
they're not in a hierarchical relationship, I don't get the "output filename
collision" warning. The greater version number gets documented and appears in
the sidebar.
Why this is important
I found out about this through an issue filed with the book.
The print versions of The Rust Programming Language instruct the reader to add
rand = "0.3.14"
to theirCargo.toml
, then runcargo doc --open
and observethat they now have the documentation for
rand
locally. This no longer works,and I am unfortunately unable to change the paper already in circulation. 😢
I haven't run the stats on crates.io's database yet, but the semver trick is
widely known, recommended, and used, especially in popular crates.
I can also see people wanting the documentation of different versions
available in their local documentation; see this SO question
for what I think is an example. While using docs.rs and picking the version
you want to look at explicitly is probably a much more common workflow, it seems
more "correct" to offer local docs for each version of a crate in the dependency tree, which I know is complicated and related to rust-lang/rust#56169 and rust-lang/rust#61378.
Version
The text was updated successfully, but these errors were encountered: