rust-lang / rust-lang/rust

rustdoc: make linking to examples easier and detect dead links

Open
#130,493 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

When writing module-level or other high-level documentation, I often want to link to our examples to show users how to do something in more detail. See https://github.com/bevyengine/bevy/pull/15056 for an example of this problem.

This is distinct from the automatically generated links to examples, rustdoc-scrape-examples, (which are great!): we want to be able to manually link to specific examples.

@GuillaumeGomez pointed out that this can be done in part using relative paths, e.g. ../../src/custom_loop/custom_loop.rs.html#19. However, this is very fragile: any change to either file breaks the link with no tooling to detect the breakage. This functionality is also undocumented, and could be broken by rustdoc / docs.rs at any time.

To add full support, he thinks we might need an intra-doc link extension to make it work.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing rustdoc-scrape-examples behavior and the example described in PR #15056, then examine how the relative-path approach is currently handled. Done means rustdoc provides a documented, stable way to link to specific examples and detects links that no longer resolve.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.