You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can also refer to items with generic parameters like `Vec<T>`. The link will
34
49
resolve as if you had written ``[`Vec<T>`](Vec)``. Fully-qualified syntax (for example,
@@ -53,7 +68,7 @@ impl<T> AsyncReceiver<T> {
53
68
}
54
69
```
55
70
56
-
You can also link to sections using URL fragment specifiers:
71
+
Rustdoc allows using URL fragment specifiers, just like a normal link:
57
72
58
73
```rust
59
74
/// This is a special implementation of [positional parameters].
@@ -62,9 +77,13 @@ You can also link to sections using URL fragment specifiers:
62
77
structMySpecialFormatter;
63
78
```
64
79
65
-
Paths in Rust have three namespaces: type, value, and macro. Item names must be
66
-
unique within their namespace, but can overlap with items outside of their
67
-
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@`:
80
+
## Namespaces and Disambiguators
81
+
82
+
Paths in Rust have three namespaces: type, value, and macro. Item names must be unique within
83
+
their namespace, but can overlap with items outside of their namespace. In case of ambiguity,
84
+
rustdoc will warn about the ambiguity and ask you to disambiguate, which can be done by using a
85
+
prefix like `struct@`, `enum@`, `type@`, `trait@`, `union@`, `const@`, `static@`, `value@`,
86
+
`fn@`, `function@`, `mod@`, `module@`, `method@`, `prim@`, `primitive@`, `macro@`, or `derive@`:
68
87
69
88
```rust
70
89
/// See also: [`Foo`](struct@Foo)
@@ -76,6 +95,9 @@ struct Foo {}
76
95
fnFoo() {}
77
96
```
78
97
98
+
These prefixes will be stripped when displayed in the documentation, so `[struct@Foo]`
99
+
will be rendered as `Foo`.
100
+
79
101
You can also disambiguate for functions by adding `()` after the function name,
80
102
or for macros by adding `!` after the macro name:
81
103
@@ -89,6 +111,32 @@ struct Foo {}
89
111
fnFoo() {}
90
112
```
91
113
92
-
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][#72243], as opposed to the module it is defined in.
114
+
## Warnings, re-exports, and scoping
115
+
116
+
Links are resolved in the current module scope, even when re-exported. If a link from another
117
+
crate fails to resolve, no warning is given.
118
+
119
+
When re-exporting an item, rustdoc allows additional documentation to it. That documentation will
120
+
be resolved in the new scope, not the original, allowing you to link to items in the current
121
+
crate. The new links will still give a warning if they fail to resolve.
122
+
123
+
```rust
124
+
/// See also [foo()]
125
+
pubusestd::process::Command;
126
+
127
+
pubfnfoo() {}
128
+
```
129
+
130
+
This is especially useful for proc-macros, which must always be in their own dedicated crate.
131
+
132
+
Note: Because of how `macro_rules!` macros are scoped in Rust, the intra-doc links of a
133
+
`macro_rules!` macro will be resolved [relative to the crate root][#72243], as opposed to the
134
+
module it is defined in.
135
+
136
+
If links do not look 'sufficiently like' an intra-doc link, they will be ignored and no warning
137
+
will be given, even if the link fails to resolve. For example, any link containing `/` or `[]`
138
+
characters will be ignored. You can see the full criteria for 'sufficiently like' in [the source
0 commit comments