Skip to content

Commit 30adb53

Browse files
talk about intra-links
1 parent 373b2cd commit 30adb53

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,48 @@ future.
3131

3232
Attempting to use these error numbers on stable will result in the code sample being interpreted as
3333
plain text.
34+
35+
## Linking to items by type
36+
37+
As designed in [RFC 1946], Rustdoc can parse paths to items when you use them as links. To resolve
38+
these type names, it uses the items currently in-scope, either by declaration or by `use` statement.
39+
For modules, the "active scope" depends on whether the documentation is written outside the module
40+
(as `///` comments on the `mod` statement) or inside the module (at `//!` comments inside the file
41+
or block). For all other items, it uses the enclosing module's scope.
42+
43+
[RFC 1946]: https://github.com/rust-lang/rfcs/pull/1946
44+
45+
For example, in the following code:
46+
47+
```rust
48+
/// Does the thing.
49+
pub fn do_the_thing(_: SomeType) {
50+
println!("Let's do the thing!");
51+
}
52+
53+
/// Token you use to [`do_the_thing`].
54+
pub struct SomeType;
55+
```
56+
57+
The link to ``[`do_the_thing`]`` in `SomeType`'s docs will properly link to the page for `fn
58+
do_the_thing`. Note that here, rustdoc will insert the link target for you, but manually writing the
59+
target out also works:
60+
61+
```rust
62+
pub mod some_module {
63+
/// Token you use to do the thing.
64+
pub struct SomeStruct;
65+
}
66+
67+
/// Does the thing. Requires one [`SomeStruct`] for the thing to work.
68+
///
69+
/// [`SomeStruct`]: some_module::SomeStruct
70+
pub fn do_the_thing(_: some_module::SomeStruct) {
71+
println!("Let's do the thing!");
72+
}
73+
```
74+
75+
For more details, check out [the RFC][RFC 1946], and see [the tracking issue][43466] for more
76+
information about what parts of the feature are available.
77+
78+
[43466]: https://github.com/rust-lang/rust/issues/43466

0 commit comments

Comments
 (0)