Tracking issue for -Zrustdoc-map
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 15.5k
- Forks
- 3k
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 51
Description
Original issue: #6279
Implementation: #8287
Documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#rustdoc-map
Issues: https://github.com/rust-lang/cargo/labels/Z-rustdoc-map
Summary
This feature adds the ability for Cargo to pass external documentation mappings to rustdoc, so that links to dependencies will use those external sites (like docs.rs). See the documentation for details on how to use it.
Unresolved issues
- Does not properly handle renamed dependencies. The links rustdoc generates are to the package name, not the renamed name. Cargo is written to pass in package names, but if there are multiple dependencies to the same package, it won't work properly.
- May be fixed by https://github.com/rust-lang/rust/pull/143465
- If there are multiple versions of the same package within the dep graph, rustdoc will only link to one of them. To fix this, Cargo would need to pass metadata info into rustdoc (such as the package version).
- May be fixed by https://github.com/rust-lang/rust/pull/143465
- If a dependency is built with different features than what is on docs.rs, some links may break. This is probably unsolvable.
- This increases the command-line length significantly. Before stabilizing, we may want to consider addressing that. I'm not sure if it would make sense to change rustdoc's interface, or to use response files?
- Decide if Cargo should pass mappings for transitive dependencies (currently it does not). This normally isn't an issue, but can arise for re-exports (see the alt_registry test for an example). I'm not sure if this is a bug in rustdoc or not (there is a large number of issues regarding reexports and rustdoc). Cargo could include these, but this would make the command-line length even longer. Not sure what to do here.
- The config value does not support being set via environment variables (like
CARGO_CONFIG_DOC_EXTERN_MAP_REGISTRIES_CRATES_IO="…"). This would be very difficult to support, because Cargo doesn't retain the registry name in SourceId. I looked into fixing that, but it is very difficult, and hard to make it reliable. I would lean towards not bothering with this (it has similar issues as thesourcetable). - Add a config option to control the default deps behavior of
cargo doc. I can think of 3 options: all-deps, no-deps, direct-deps only. I think this would be useful, otherwise to use the rustdoc-map, one would always need to pass--no-deps. This would probably also need a new command-line flag to override the config option (maybe a generalization of--no-deps). - Consider changing the defaults. This is an important part of the UX story.
- Default to
crates-io = "https://docs.rs/". I think this should be relatively safe, since it only enhances the current behavior (people who use --no-deps will now have links instead of no links in their docs). DONE: #8877 - Change default of the deps behavior of
cargo doc. I would prefer to get more community feedback to see what makes sense. Two options:- Direct dependencies only. I think this option is more realistic. It retains local browsing and indexing, and removes transitive dependencies which are usually not interesting. This would not engage rustdoc-map, so this is somewhat orthogonal.
- Default to
--no-deps. This would engage rustdoc-map, but is a much more drastic change. The user would not have local indexing available.
- Default to
- Should there be some way for the crate author to control the link destination? The
documentationURL set inCargo.tomlis never consulted. I think this is unlikely to work with rustdoc, because it expects a certain structure to the API docs, and documentation URLs often point to user guides, or other things that aren't API docs. The#![doc(html_root_url = "...")]attribute is overridden by the--extern-html-root-urlflag. This may be a good or bad thing depending on your perspective (should the user have control, or should the crate author?).
Future extensions
These things can be done after stabilization, but should be considered to ensure this feature doesn't make them more difficult.
- Single tab browsing. This would be a mode where the std docs are merged with the local crate's docs so that the std docs are shown in the same place (and included in the index). This could be expressed with something like
doc.extern-map.std = "include"or something like that. (Or maybe just use build-std?) https://github.com/rust-lang/cargo/issues/6279#issuecomment-629670934 - Direct-dependencies only. Often transitive dependencies aren't that interesting, and take up a lot of space in the output, and clog the search index. Some users want the ability to (locally) document their package + direct dependencies only. I think this could be implemented with some kind of command-line flag, perhaps with a config setting in the
[doc]table.--extern-html-root-urlflag will automatically handle second-level dependencies. #2025 #2801 #6421 https://crates.io/crates/cargo-makedocs - Manual-exclusions. Sometimes there are specific dependencies that are very expensive to document locally, but you still want everything else. I think this could be implemented with a command-line flag (
--exclude winapi?), and the rustdoc-map feature would automatically link those excluded crates' items to docs.rs. This could also be added to the[doc]table. #4049
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the implementation in #8287 and the unstable Cargo documentation linked in this issue. Review the unresolved-issues checklist and related Rust pull request #143465; done means reaching a maintainer decision and resolving or explicitly closing the remaining stabilization questions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100