Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Links

This chapter explains how links should be handled by the Reference. Several of these capabilities are provided by mdbook-spec.

See also the linkchecker tests for testing links.

Rules can be linked to by their ID using Markdown, with the destination set to the rule ID. Automatic link references allow any rule to be referred to from any page in the book.

Direct label link: [names.preludes.lang]

Destination label link (custom link text): [language prelude][names.preludes.lang]

Definition link: [namespace kinds]

[namespace kinds]: names.namespaces.kinds

You should link to the standard library without specifying a URL, in a fashion similar to rustdoc intra-doc links. Some examples:

We can link to the page on Option:

[`std::option::Option`]

In these links, generics are ignored and can be included:

[`std::option::Option<T>`]

If we don’t want the full path in the text, we can write:

[`Option`](std::option::Option)

Macros can end in !. This can be helpful for disambiguation. For example, this refers to the macro rather than the module:

[`alloc::vec!`]

Explicit namespace disambiguation is also supported:

[`std::vec`](mod@std::vec)

Beware of some limitations, for example:

When running into a rustdoc limitation, consider manually linking to the correct page using a relative link. For example, ../std/arch/macro.is_x86_feature_detected.html.

When rendering the Reference locally, it uses relative links by default to conform with how the books are published. This probably isn’t what you want, so you will usually want to set the SPEC_RELATIVE=0 environment variable so that the links go to the live site instead.

Link definitions are automatically generated for all grammar production names. See grammar automatic linking for more.

This attribute uses the [MetaWord] syntax.

Explicit grammar links can have the `grammar-` prefix like [Type][grammar-Type].

Links to other books published with the Reference should be relative links pointing to the corresponding book. This allows the links to point to the correct version, to work with the offline docs, and to be checked by the linkchecker. For example:

See [`-C panic`].

[`-C panic`]: ../rustc/codegen-options/index.html#panic

When possible, internal links should use rule links or grammar links. Otherwise, links should be relative to the file path and use the .md extension.

- Rule link: [language prelude][names.preludes.lang]
- Grammar link: [MetaWord]
- Internal link: [Modules](items/modules.md#attributes-on-modules)