Description
This is a follow-up issue from a discussion on Discord with @Nemo157 about a bug in a crate's doc trying to link a type in another crate, which is actually a re-export from a third crate (dependency-of-dependency).
Description
The situation is as follow:
- The Bevy game engine has a top-level "facade"* crate
bevy
that projects are expected to take a dependency on. - Bevy itself is implemented in many crates,
bevy_XXX
, and the public types are re-exported from the facade. - A third-party crate which wants to link a doc to a Bevy type will typically attempt to use the same module path as the Rust code it uses, that is a path starting with the facade
bevy::
.
*I'm using "facade" in this issue as what I think it means, a "top-level" crate that re-export many other "internal" ones, but maybe I misunderstood the meaning given in rust-lang/rust#22083. If so, sorry for the confusion, and please take "facade" as the meaning I just described.
The result is that unfortunately links on docs.rs are broken, rendering verbatim instead of being actual links to the HTML page of the documentation of the type.
Bug example
Note: To avoid confusion, the example is from my crate bevy_tweening
, which is not an official Bevy crate, and not part of the official repo. So in particular that crate has no direct access to internal Bevy crates, and should be seen as "third-party".
See an example of published crate here, where the [Entity]
link toward the top of the page doesn't link anywhere (the HTML link contains the verbatim Rust path bevy::ecs::entity::Entity
). The source code those docs are generated from is:
For reference (as for some reason GitHub refuses to expand the above link into code) the link is:
/// Animate the position ([`Transform::translation`]) of an [`Entity`]:
///
/// ...
///
/// [`Entity`]: bevy::ecs::entity::Entity
The Entity
type is defined in the internal crate bevy_ecs
, then re-exported in the facade crate bevy
under the bevy::ecs::entity::Entity
path.
Repro steps
I'm mentioning it here for completeness because @Nemo157 provided the command to run to replicate what docs.rs does, to test this:
- First, delete old docs, as otherwise
rustdoc
seem to link them :rm -rf target/doc
or similar for other OSes - Then run
cargo doc -Zrustdoc-map --no-deps
Workaround
A workaround would be to directly link the internal type. Unfortunately since Bevy uses a facade crate, a third-party crate typically does not directly take a dependency to those Bevy internal crates, only to the facade, so simply changing the link makes the build fail. This means in addition of changing all broken links to target internal Bevy crates, a crate maintainer has to add a docs.rs-specific feature to depend on all those internal crates for documentation purpose only.
The html_root_url
attribute was also mentioned, and I'm chatting with the Bevy docs team (CC: @alice-i-cecile) to see if we can try it, but we haven't yet.
Related issues
As explained by @Nemo157 on Discord, the scenario detailed above is likely related to rust-lang/rust#22083 and rust-lang/rfcs#3011, although it was under our impression that those issues do not cover entirely the problem at hand, and in particular the dependency-of-dependency linking.