Skip to content

Commit 8f5be35

Browse files
committed
Clarify disambiguation rules
1 parent be38090 commit 8f5be35

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

text/1946-intra-rustdoc-links.md

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -284,30 +284,37 @@ To be able to link to each item,
284284
we'll need a way to disambiguate the namespaces.
285285
Our proposal is this:
286286

287-
- Links to types are written as described earlier,
288-
with no pre- or suffix,
289-
e.g., `Look at the [FOO] trait`.
290-
For consistency,
291-
it is also possible to prefix the type with the concrete item type:
292-
- Links to `struct`s can be prefixed with `struct `,
287+
- In unambiguous cases paths can be written as described earlier,
288+
with no pre- or suffix, e.g., `Look at the [FOO] trait`. This also
289+
applies to modules and tuple structs which exist in both namespaces.
290+
Rustdoc will throw an error if you use a non-disambiguated path in
291+
the case of there being a value in both the type and value namespace.
292+
Non-disambiguated paths cannot be used to link to macros.
293+
- Links to types can be disambiguated by prefixing them with the concrete
294+
item type:
295+
- Links to `struct`s can be prefixed with `struct@`,
293296
e.g., `See [struct@Foo]`.
294-
- Links to `enum`s can be prefixed with `enum `,
297+
- Links to `enum`s can be prefixed with `enum@`,
295298
e.g., `See [enum@foo]`.
296-
- Links to type aliases can be prefixed with `type `,
299+
- Links to type aliases can be prefixed with `type@`,
297300
e.g., `See [type@foo]`.
298-
- Links to modules can be prefixed with `mod `,
301+
- Links to modules can be prefixed with `mod@`,
299302
e.g., `See [mod@foo]`.
300303
- In links to macros,
301-
the link label must end with a `!`,
304+
the link label _must_ end with a `!`,
302305
e.g., `Look at the [FOO!] macro`.
303-
- For links to values, we differentiate three cases:
304-
- Links to functions are written with a `()` suffix,
306+
- For disambiguating links to values, we differentiate three cases:
307+
- Links to functions can be written with a `()` suffix,
305308
e.g., `Also see the [foo()] function`.
306-
- Links to constants are prefixed with `const `,
309+
- Links to constants are prefixed with `const@`,
307310
e.g., `As defined in [const@FOO].`
308-
- Links to statics are prefixed with `static `,
311+
- Links to statics are prefixed with `static@`,
309312
e.g., `See [static@FOO]`.
310313

314+
For disambiguation markers using an `@`, in implied shortcut links
315+
you can use a space instead of the `@`. In other words, `[struct Foo]`
316+
is fine (and preferred).
317+
311318
It should be noted that in the RFC discussion it was determined
312319
that exact knowledge of the item type
313320
should not be necessary; only knowing the namespace should suffice.
@@ -317,7 +324,6 @@ with the wrong prefix that is in the same namespace.
317324
E.g., given an `struct Foo`, it may be possible to link to it using `[enum Foo]`,
318325
or, given a `mod bar`, it may be possible to link to that using `[struct bar]`.
319326

320-
321327
## Errors
322328
[errors]: #errors
323329

0 commit comments

Comments
 (0)