Update rustdoc intra-doc link docs

* Describe generic parameters feature
* Make general improvements to the docs
This commit is contained in:
Camelid 2020-10-03 15:44:53 -07:00
parent 6df21a326e
commit b9c299effd
4 changed files with 40 additions and 13 deletions

View File

@ -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)

View File

@ -1,4 +1,4 @@
# Advanced Features
# Advanced features
The features listed on this page fall outside the rest of the main categories.

View File

@ -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<T>`. The link will
resolve as if you had written ``[`Vec<T>`](Vec)``. Fully-qualified syntax (for example,
`<Vec as IntoIterator>::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<T>`] with support for [`std::future`].
///
/// You can obtain a [`std::future::Future`] by calling [`Self::recv()`].
pub struct AsyncReceiver<T> {
@ -44,13 +56,15 @@ impl<T> AsyncReceiver<T> {
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.

View File

@ -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!