@@ -24,7 +24,7 @@ pub struct Foo4;
24
24
pub struct Bar ;
25
25
```
26
26
27
- Unlike normal markdown , ` [bar][Bar] ` syntax is also supported without needing a
27
+ Unlike normal Markdown , ` [bar][Bar] ` syntax is also supported without needing a
28
28
` [Bar]: ... ` reference link, and links are case-sensitive.
29
29
30
30
Backticks around the link will be stripped, so `` [`Option`] `` will correctly
@@ -37,14 +37,14 @@ You can refer to anything in scope, and use paths, including `Self`, `self`, `su
37
37
trait implementations] [ #79682 ] . Rustdoc also supports linking to the following primitives, which
38
38
have no path and cannot be imported:
39
39
40
- - [ ` slice ` ] ( https://doc.rust-lang.org /std/primitive.slice.html)
41
- - [ ` array ` ] ( https://doc.rust-lang.org /std/primitive.array.html)
42
- - [ ` tuple ` ] ( https://doc.rust-lang.org /std/primitive.tuple.html)
43
- - [ ` unit ` ] ( https://doc.rust-lang.org /std/primitive.unit.html)
44
- - [ ` fn ` ] ( https://doc.rust-lang.org /std/primitive.fn.html)
45
- - [ ` pointer ` ] ( https://doc.rust-lang.org /std/primitive.pointer.html) , ` * ` , ` *const ` , or ` *mut `
46
- - [ ` reference ` ] ( https://doc.rust-lang.org /std/primitive.reference.html) , ` & ` , or ` &mut `
47
- - [ ` never ` ] ( https://doc.rust-lang.org /std/primitive.never.html) or ` ! `
40
+ - [ ` slice ` ] ( ../.. /std/primitive.slice.html)
41
+ - [ ` array ` ] ( ../.. /std/primitive.array.html)
42
+ - [ ` tuple ` ] ( ../.. /std/primitive.tuple.html)
43
+ - [ ` unit ` ] ( ../.. /std/primitive.unit.html)
44
+ - [ ` fn ` ] ( ../.. /std/primitive.fn.html)
45
+ - [ ` pointer ` ] ( ../.. /std/primitive.pointer.html) , ` * ` , ` *const ` , or ` *mut `
46
+ - [ ` reference ` ] ( ../.. /std/primitive.reference.html) , ` & ` , or ` &mut `
47
+ - [ ` never ` ] ( ../.. /std/primitive.never.html) or ` ! `
48
48
49
49
[ #79682 ] : https://github.com/rust-lang/rust/pull/79682
50
50
@@ -83,10 +83,8 @@ struct MySpecialFormatter;
83
83
## Namespaces and Disambiguators
84
84
85
85
Paths in Rust have three namespaces: type, value, and macro. Item names must be unique within
86
- their namespace, but can overlap with items outside of their namespace. In case of ambiguity,
87
- rustdoc will warn about the ambiguity and ask you to disambiguate, which can be done by using a
88
- prefix like ` struct@ ` , ` enum@ ` , ` type@ ` , ` trait@ ` , ` union@ ` , ` const@ ` , ` static@ ` , ` value@ ` ,
89
- ` fn@ ` , ` function@ ` , ` mod@ ` , ` module@ ` , ` method@ ` , ` prim@ ` , ` primitive@ ` , ` macro@ ` , or ` derive@ ` :
86
+ their namespace, but can overlap with items in other namespaces. In case of ambiguity,
87
+ rustdoc will warn about the ambiguity and ask you to disambiguate.
90
88
91
89
``` rust
92
90
/// See also: [`Foo`](struct@Foo)
@@ -98,30 +96,48 @@ struct Foo {}
98
96
fn Foo () {}
99
97
```
100
98
99
+ The following prefixes can be used:
100
+
101
+ - ` struct@ `
102
+ - ` enum@ `
103
+ - ` type@ `
104
+ - ` trait@ `
105
+ - ` union@ `
106
+ - ` const@ `
107
+ - ` static@ `
108
+ - ` value@ `
109
+ - ` fn@ ` / ` function@ ` / ` method@ `
110
+ - ` mod@ ` / ` module@ `
111
+ - ` prim@ ` / ` primitive@ `
112
+ - ` macro@ `
113
+ - ` derive@ `
114
+
101
115
These prefixes will be stripped when displayed in the documentation, so ` [struct@Foo] `
102
116
will be rendered as ` Foo ` .
103
117
104
118
You can also disambiguate for functions by adding ` () ` after the function name,
105
119
or for macros by adding ` ! ` after the macro name:
106
120
107
121
``` rust
108
- /// See also: [`Foo`](struct@Foo)
109
- struct Bar ;
122
+ /// This is different from [`foo!`]
123
+ fn foo () {}
110
124
111
- /// This is different from [`Foo ()`]
112
- struct Foo {}
113
-
114
- fn Foo () { }
125
+ /// This is different from [`foo ()`]
126
+ macro_rules! foo {
127
+ () => {}
128
+ }
115
129
```
116
130
117
131
## Warnings, re-exports, and scoping
118
132
119
- Links are resolved in the current module scope, even when re-exported. If a link from another
120
- crate fails to resolve, no warning is given.
133
+ Links are resolved in the scope of the module where the item is defined, even
134
+ when the item is re-exported. If a link from another crate fails to resolve, no
135
+ warning is given.
121
136
122
- When re-exporting an item, rustdoc allows additional documentation to it. That documentation will
123
- be resolved in the new scope, not the original, allowing you to link to items in the current
124
- crate. The new links will still give a warning if they fail to resolve.
137
+ When re-exporting an item, rustdoc allows adding additional documentation to it.
138
+ That additional documentation will be resolved in scope of the re-export, not
139
+ the original, allowing you to link to items in the new crate. The new links
140
+ will still give a warning if they fail to resolve.
125
141
126
142
``` rust
127
143
/// See also [foo()]
@@ -130,7 +146,7 @@ pub use std::process::Command;
130
146
pub fn foo () {}
131
147
```
132
148
133
- This is especially useful for proc-macros, which must always be in their own dedicated crate.
149
+ This is especially useful for proc-macros, which must always be defined in their own dedicated crate.
134
150
135
151
Note: Because of how ` macro_rules! ` macros are scoped in Rust, the intra-doc links of a
136
152
` macro_rules! ` macro will be resolved [ relative to the crate root] [ #72243 ] , as opposed to the
0 commit comments