Skip to content

Commit db0b416

Browse files
committed
Address review comments
- Improve wording - Use relative links - Use a proper list instead of a wall of text - Improve examples
1 parent d5392d1 commit db0b416

File tree

1 file changed

+41
-25
lines changed

1 file changed

+41
-25
lines changed

src/doc/rustdoc/src/linking-to-items-by-name.md

+41-25
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct Foo4;
2424
pub struct Bar;
2525
```
2626

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
2828
`[Bar]: ...` reference link, and links are case-sensitive.
2929

3030
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
3737
trait implementations][#79682]. Rustdoc also supports linking to the following primitives, which
3838
have no path and cannot be imported:
3939

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 `!`
4848

4949
[#79682]: https://github.com/rust-lang/rust/pull/79682
5050

@@ -83,10 +83,8 @@ struct MySpecialFormatter;
8383
## Namespaces and Disambiguators
8484

8585
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.
9088

9189
```rust
9290
/// See also: [`Foo`](struct@Foo)
@@ -98,30 +96,48 @@ struct Foo {}
9896
fn Foo() {}
9997
```
10098

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+
101115
These prefixes will be stripped when displayed in the documentation, so `[struct@Foo]`
102116
will be rendered as `Foo`.
103117

104118
You can also disambiguate for functions by adding `()` after the function name,
105119
or for macros by adding `!` after the macro name:
106120

107121
```rust
108-
/// See also: [`Foo`](struct@Foo)
109-
struct Bar;
122+
/// This is different from [`foo!`]
123+
fn foo() {}
110124

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+
}
115129
```
116130

117131
## Warnings, re-exports, and scoping
118132

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.
121136

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.
125141

126142
```rust
127143
/// See also [foo()]
@@ -130,7 +146,7 @@ pub use std::process::Command;
130146
pub fn foo() {}
131147
```
132148

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.
134150

135151
Note: Because of how `macro_rules!` macros are scoped in Rust, the intra-doc links of a
136152
`macro_rules!` macro will be resolved [relative to the crate root][#72243], as opposed to the

0 commit comments

Comments
 (0)