Skip to content

rustdoc: make linking to examples easier and detect dead links #130493

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

Open
alice-i-cecile opened this issue Sep 17, 2024 · 4 comments · May be fixed by #132792
Open

rustdoc: make linking to examples easier and detect dead links #130493

alice-i-cecile opened this issue Sep 17, 2024 · 4 comments · May be fixed by #132792
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@alice-i-cecile
Copy link

alice-i-cecile commented Sep 17, 2024

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 bevyengine/bevy#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.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 17, 2024
@alice-i-cecile alice-i-cecile added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 17, 2024
@alice-i-cecile alice-i-cecile changed the title rustdoc: make linking to examples easier rustdoc: make linking to examples easier and detect dead links Sep 17, 2024
@GuillaumeGomez
Copy link
Member

I think the best course of action here would be to extend intra-doc links and give them possibility to link to an example. My best idea at the moment is to the prepend the example path with example:. It would look like this:

/// Oh what a nice [example][example:path/to/example]!
/// Here is [another one](example:path/to/another one]!

What do you think?

@alice-i-cecile
Copy link
Author

Yep, that looks great, assuming the dead intradoc links lint triggers correctly.

@GuillaumeGomez
Copy link
Member

Coming back to this, this disambiguator syntax @ would work too and would be coherent with the rest:

/// Oh what a nice [example][example@example_name]!

@GuillaumeGomez
Copy link
Member

Opened the PR to add this feature: #132792

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@GuillaumeGomez @alice-i-cecile @rustbot and others