Skip to content

Commit 4c85356

Browse files
committed
Move standard library links to the links chapter
1 parent 074406e commit 4c85356

File tree

3 files changed

+54
-46
lines changed

3 files changed

+54
-46
lines changed

contributor-guide/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- [Language rules]()
1414
- [rustc test annotations]()
1515
- [Examples](examples.md)
16-
- [Links]()
16+
- [Links](links.md)
1717
- [Rust grammar](grammar.md)
1818
- [Attributes](attributes.md)
1919
- [Style guide]()

contributor-guide/src/links.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Links
2+
3+
This chapter explains how links should be handled by the Reference. Several of these capabilities are provided by [`mdbook-spec`](tooling/mdbook-spec.md).
4+
5+
See also the [linkchecker tests](tests.md#linkcheck) for testing links.
6+
7+
## Standard library links
8+
9+
You should link to the standard library without specifying a URL in a fashion similar to [rustdoc intra-doc links][intra]. Some examples:
10+
11+
We can link to the page on `Option`:
12+
13+
```markdown
14+
[`std::option::Option`]
15+
```
16+
17+
In these links, generics are ignored and can be included:
18+
19+
```markdown
20+
[`std::option::Option<T>`]
21+
```
22+
23+
If we don't want the full path in the text, we can write:
24+
25+
```markdown
26+
[`Option`](std::option::Option)
27+
```
28+
29+
Macros can end in `!`. This can be helpful for disambiguation. For example, this refers to the macro rather than the module:
30+
31+
```markdown
32+
[`alloc::vec!`]
33+
```
34+
35+
Explicit namespace disambiguation is also supported:
36+
37+
```markdown
38+
[`std::vec`](mod@std::vec)
39+
```
40+
41+
Beware there are some limitations, for example:
42+
43+
- Links to rexports from `std_arch` don't work due to <https://github.com/rust-lang/rust/issues/96506>.
44+
- Links to keywords aren't supported.
45+
- Links to trait impls where the trait is not in the prelude doesn't work. Traits must be in scope, and there currently isn't a way to add those.
46+
- If there are multiple generic implementations, it will link to one randomly (see <https://github.com/rust-lang/rust/issues/76895>).
47+
48+
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`.
49+
50+
When rendering the Reference locally, by default it uses relative links to conform with how the books are published. This probably isn't what you want, so you usually will want to set the [`SPEC_RELATIVE=0` environment variable][rel] so that the links go to the live site instead.
51+
52+
[intra]: https://doc.rust-lang.org/rustdoc/write-documentation/linking-to-items-by-name.html
53+
[rel]: tooling/building.md#spec_relative

docs/authoring.md

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -69,51 +69,6 @@ We are not expecting 100% coverage at any time. Although it would be nice, it is
6969

7070
[appendix]: https://doc.rust-lang.org/nightly/reference/test-summary.html
7171

72-
### Standard library links
73-
74-
You should link to the standard library without specifying a URL in a fashion similar to [rustdoc intra-doc links][intra]. Some examples:
75-
76-
We can link to the page on `Option`:
77-
78-
```markdown
79-
[`std::option::Option`]
80-
```
81-
82-
In these links, generics are ignored and can be included:
83-
84-
```markdown
85-
[`std::option::Option<T>`]
86-
```
87-
88-
If we don't want the full path in the text, we can write:
89-
90-
```markdown
91-
[`Option`](std::option::Option)
92-
```
93-
94-
Macros can end in `!`. This can be helpful for disambiguation. For example, this refers to the macro rather than the module:
95-
96-
```markdown
97-
[`alloc::vec!`]
98-
```
99-
100-
Explicit namespace disambiguation is also supported:
101-
102-
```markdown
103-
[`std::vec`](mod@std::vec)
104-
```
105-
106-
Beware there are some limitations, for example:
107-
108-
- Links to rexports from `std_arch` don't work due to <https://github.com/rust-lang/rust/issues/96506>.
109-
- Links to keywords aren't supported.
110-
- Links to trait impls where the trait is not in the prelude doesn't work. Traits must be in scope, and there currently isn't a way to add those.
111-
- If there are multiple generic implementations, it will link to one randomly (see <https://github.com/rust-lang/rust/issues/76895>).
112-
113-
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`.
114-
115-
[intra]: https://doc.rust-lang.org/rustdoc/write-documentation/linking-to-items-by-name.html
116-
11772
## Style
11873

11974
Idioms and styling:

0 commit comments

Comments
 (0)