diff --git a/src/doc/rustdoc/src/SUMMARY.md b/src/doc/rustdoc/src/SUMMARY.md index 93454b4f909..a3fa525be1d 100644 --- a/src/doc/rustdoc/src/SUMMARY.md +++ b/src/doc/rustdoc/src/SUMMARY.md @@ -8,5 +8,5 @@ - [Linking to items by name](linking-to-items-by-name.md) - [Lints](lints.md) - [Passes](passes.md) -- [Advanced Features](advanced-features.md) +- [Advanced features](advanced-features.md) - [Unstable features](unstable-features.md) diff --git a/src/doc/rustdoc/src/advanced-features.md b/src/doc/rustdoc/src/advanced-features.md index 8be9489c617..5128ff13b7a 100644 --- a/src/doc/rustdoc/src/advanced-features.md +++ b/src/doc/rustdoc/src/advanced-features.md @@ -1,4 +1,4 @@ -# Advanced Features +# Advanced features The features listed on this page fall outside the rest of the main categories. diff --git a/src/doc/rustdoc/src/linking-to-items-by-name.md b/src/doc/rustdoc/src/linking-to-items-by-name.md index 5e46ef583f6..26bee2974ac 100644 --- a/src/doc/rustdoc/src/linking-to-items-by-name.md +++ b/src/doc/rustdoc/src/linking-to-items-by-name.md @@ -1,6 +1,7 @@ # Linking to items by name -Rustdoc is capable of directly linking to other rustdoc pages in Markdown documentation using the path of item as a link. +Rustdoc is capable of directly linking to other rustdoc pages using the path of +the item as a link. For example, in the following code all of the links will link to the rustdoc page for `Bar`: @@ -19,15 +20,26 @@ pub struct Foo3; /// This struct is also not [`Bar`] pub struct Foo4; +/// This struct *is* [`Bar`]! pub struct Bar; ``` -You can refer to anything in scope, and use paths, including `Self`, `self`, `super`, and `crate`. You may also use `foo()` and `foo!()` to refer to methods/functions and macros respectively. Backticks around the link will be stripped. +Backticks around the link will be stripped, so ``[`Option`]`` will correctly +link to `Option`. + +You can refer to anything in scope, and use paths, including `Self`, `self`, +`super`, and `crate`. You may also use `foo()` and `foo!()` to refer to methods/functions and macros, respectively. + +You can also refer to items with generic parameters like `Vec`. The link will +resolve as if you had written ``[`Vec`](Vec)``. Fully-qualified syntax (for example, +`::into_iter()`) is [not yet supported][fqs-issue], however. + +[fqs-issue]: https://github.com/rust-lang/rust/issues/74563 ```rust,edition2018 use std::sync::mpsc::Receiver; -/// This is an version of [`Receiver`], with support for [`std::future`]. +/// This is a version of [`Receiver`] with support for [`std::future`]. /// /// You can obtain a [`std::future::Future`] by calling [`Self::recv()`]. pub struct AsyncReceiver { @@ -44,13 +56,15 @@ impl AsyncReceiver { You can also link to sections using URL fragment specifiers: ```rust -/// This is a special implementation of [positional parameters] +/// This is a special implementation of [positional parameters]. /// /// [positional parameters]: std::fmt#formatting-parameters struct MySpecialFormatter; ``` -Paths in Rust have three namespaces: type, value, and macro. Items from these namespaces are allowed to overlap. In case of ambiguity, rustdoc will warn about the ambiguity and ask you to disambiguate, which can be done by using a prefix like `struct@`, `enum@`, `type@`, `trait@`, `union@`, `const@`, `static@`, `value@`, `function@`, `mod@`, `fn@`, `module@`, `method@`, `prim@`, `primitive@`, `macro@`, or `derive@`: +Paths in Rust have three namespaces: type, value, and macro. Item names must be +unique within their namespace, but can overlap with items outside of their +namespace. In case of ambiguity, rustdoc will warn about the ambiguity and ask you to disambiguate, which can be done by using a prefix like `struct@`, `enum@`, `type@`, `trait@`, `union@`, `const@`, `static@`, `value@`, `fn@`, `function@`, `mod@`, `module@`, `method@`, `prim@`, `primitive@`, `macro@`, or `derive@`: ```rust /// See also: [`Foo`](struct@Foo) @@ -62,4 +76,17 @@ struct Foo {} fn Foo() {} ``` -Note: Because of how `macro_rules` macros are scoped in Rust, the intra-doc links of a `macro_rules` macro will be resolved relative to the crate root, as opposed to the module it is defined in. +You can also disambiguate for functions by adding `()` after the function name, +or for macros by adding `!` after the macro name: + +```rust +/// See also: [`Foo`](struct@Foo) +struct Bar; + +/// This is different from [`Foo()`] +struct Foo {} + +fn Foo() {} +``` + +Note: Because of how `macro_rules!` macros are scoped in Rust, the intra-doc links of a `macro_rules!` macro will be resolved relative to the crate root, as opposed to the module it is defined in. diff --git a/src/doc/rustdoc/src/lints.md b/src/doc/rustdoc/src/lints.md index d8c0bab2259..cb9099cd50b 100644 --- a/src/doc/rustdoc/src/lints.md +++ b/src/doc/rustdoc/src/lints.md @@ -4,18 +4,18 @@ can use them like any other lints by doing this: ```rust,ignore -#![allow(missing_docs)] // allowing the lint, no message -#![warn(missing_docs)] // warn if there is missing docs -#![deny(missing_docs)] // rustdoc will fail if there is missing docs +#![allow(missing_docs)] // allows the lint, no diagnostics will be reported +#![warn(missing_docs)] // warn if there are missing docs +#![deny(missing_docs)] // error if there are missing docs ``` Here is the list of the lints provided by `rustdoc`: ## broken_intra_doc_links -This lint **warns by default**. This lint detects when an [intra-doc link] fails to get resolved. For example: +This lint **warns by default**. This lint detects when an [intra-doc link] fails to be resolved. For example: - [intra-doc link]: linking-to-items-by-name.html +[intra-doc link]: linking-to-items-by-name.md ```rust /// I want to link to [`Nonexistent`] but it doesn't exist!