Skip to content

rustdoc: Allow paths to (partially) be ignored in links #143847

Open
@orlp

Description

@orlp

It's very common for me to refer to a particular method, function, struct, etc without wanting to mention the full path. Right now the easiest way to do this is as following:

/// See also [`my_long_function_name`](some::path::to::my_long_function_name).

This is really common in my experience (most often with Self as the path), and has three main problems:

  1. It's annoying to repeat yourself.
  2. It's error prone to repeat yourself, you could make a typo/refactor in one or the other causing them to go out of sync.
  3. It's annoying to repeat yourself.

In this issue I would like to propose a simple shorthand for the above:

/// See also [some::path::to::`my_long_function_name`].

In essence, I propose that as a preprocessing step we transform Markdown links of the form

[ <PRIVATE_PATH> :: ` <PUBLIC_PATH> ` ]

into

[ ` <PUBLIC_PATH> ` ] ( <PRIVATE_PATH> :: <PUBLIC_PATH> )

This makes writing links a lot more convenient in general, and less error prone. Two more examples, also highlighting the possibility to partially ignore a path:

[foo::`bar`]        ->    [`bar`](foo::bar)
[foo::`bar::baz`]   ->    [`bar::baz`](foo::bar::baz)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-intra-doc-linksArea: Intra-doc links, the ability to link to items in docs by nameC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions