Skip to content

Commit 63d5bee

Browse files
committed
Move intra-doc-links documentation out of unstable section
1 parent c100e72 commit 63d5bee

File tree

3 files changed

+57
-57
lines changed

3 files changed

+57
-57
lines changed

src/doc/rustdoc/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [Command-line arguments](command-line-arguments.md)
66
- [The `#[doc]` attribute](the-doc-attribute.md)
77
- [Documentation tests](documentation-tests.md)
8+
- [Linking to items by name](linking-to-items-by-name.md)
89
- [Lints](lints.md)
910
- [Passes](passes.md)
1011
- [Advanced Features](advanced-features.md)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Linking to items by name
2+
3+
Rustdoc is capable of directly linking to other rustdoc pages in Markdown documentation using the path of item as a link.
4+
5+
For example, in the following code all of the links will link to the rustdoc page for `Bar`:
6+
7+
```rust
8+
/// This struct is not [Bar]
9+
pub struct Foo1;
10+
11+
/// This struct is also not [bar](Bar)
12+
pub struct Foo2;
13+
14+
/// This struct is also not [bar][b]
15+
///
16+
/// [b]: Bar
17+
pub struct Foo3;
18+
19+
/// This struct is also not [`Bar`]
20+
pub struct Foo4;
21+
22+
pub struct Bar;
23+
```
24+
25+
You can refer to anything in scope, and use paths, including `Self`. You may also use `foo()` and `foo!()` to refer to methods/functions and macros respectively.
26+
27+
```rust,edition2018
28+
use std::sync::mpsc::Receiver;
29+
30+
/// This is an version of [`Receiver`], with support for [`std::future`].
31+
///
32+
/// You can obtain a [`std::future::Future`] by calling [`Self::recv()`].
33+
pub struct AsyncReceiver<T> {
34+
sender: Receiver<T>
35+
}
36+
37+
impl<T> AsyncReceiver<T> {
38+
pub async fn recv() -> T {
39+
unimplemented!()
40+
}
41+
}
42+
```
43+
44+
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@` , `macro@`, or `derive@`:
45+
46+
```rust
47+
/// See also: [`Foo`](struct@Foo)
48+
struct Bar;
49+
50+
/// This is different from [`Foo`](fn@Foo)
51+
struct Foo {}
52+
53+
fn Foo() {}
54+
```
55+
56+
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.

src/doc/rustdoc/src/unstable-features.md

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -38,63 +38,6 @@ future.
3838
Attempting to use these error numbers on stable will result in the code sample being interpreted as
3939
plain text.
4040

41-
### Linking to items by name
42-
43-
Rustdoc is capable of directly linking to other rustdoc pages in Markdown documentation using the path of item as a link.
44-
45-
For example, in the following code all of the links will link to the rustdoc page for `Bar`:
46-
47-
```rust
48-
/// This struct is not [Bar]
49-
pub struct Foo1;
50-
51-
/// This struct is also not [bar](Bar)
52-
pub struct Foo2;
53-
54-
/// This struct is also not [bar][b]
55-
///
56-
/// [b]: Bar
57-
pub struct Foo3;
58-
59-
/// This struct is also not [`Bar`]
60-
pub struct Foo4;
61-
62-
pub struct Bar;
63-
```
64-
65-
You can refer to anything in scope, and use paths, including `Self`. You may also use `foo()` and `foo!()` to refer to methods/functions and macros respectively.
66-
67-
```rust,edition2018
68-
use std::sync::mpsc::Receiver;
69-
70-
/// This is an version of [`Receiver`], with support for [`std::future`].
71-
///
72-
/// You can obtain a [`std::future::Future`] by calling [`Self::recv()`].
73-
pub struct AsyncReceiver<T> {
74-
sender: Receiver<T>
75-
}
76-
77-
impl<T> AsyncReceiver<T> {
78-
pub async fn recv() -> T {
79-
unimplemented!()
80-
}
81-
}
82-
```
83-
84-
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@`:
85-
86-
```rust
87-
/// See also: [`Foo`](struct@Foo)
88-
struct Bar;
89-
90-
/// This is different from [`Foo`](fn@Foo)
91-
struct Foo {}
92-
93-
fn Foo() {}
94-
```
95-
96-
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.
97-
9841
## Extensions to the `#[doc]` attribute
9942

10043
These features operate by extending the `#[doc]` attribute, and thus can be caught by the compiler

0 commit comments

Comments
 (0)